Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make WebGPU classes "nominal types" (not structural types) #11

Merged
merged 1 commit into from
Jan 7, 2020
Merged

Make WebGPU classes "nominal types" (not structural types) #11

merged 1 commit into from
Jan 7, 2020

Conversation

kainino0x
Copy link
Collaborator

This prevents bugs like:

const view: GPUTextureView = device.createTexture(desc); // no .createView()

Technique:
https://michalzalecki.com/nominal-typing-in-typescript/#approach-1-class-with-a-private-property

@kainino0x kainino0x requested a review from austinEng January 7, 2020 18:45
Copy link
Collaborator

@austinEng austinEng left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool, that's a nifty trick.

Btw, did you see microsoft/TypeScript#33038 is coming soon?

@kainino0x
Copy link
Collaborator Author

hm, I didn't see that. Looks like it works for newtypes (which is awesome!) but that makes it clunky for nominally-typed classes. We'll see how it turns out.

This prevents bugs like:

  const view: GPUTextureView = device.createTexture(desc); // no .createView()

Technique:
https://michalzalecki.com/nominal-typing-in-typescript/#approach-1-class-with-a-private-property
@kainino0x kainino0x merged commit 0e38187 into gpuweb:master Jan 7, 2020
@kainino0x kainino0x deleted the nominal-types branch January 7, 2020 19:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants