Skip to content

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

Merged
kainino0x merged 1 commit into
gpuweb:masterfrom
kainino0x:nominal-types
Jan 7, 2020
Merged

Make WebGPU classes "nominal types" (not structural types)#11
kainino0x merged 1 commit into
gpuweb:masterfrom
kainino0x:nominal-types

Conversation

@kainino0x

Copy link
Copy Markdown
Collaborator

This prevents bugs like:

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

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

@austinEngaustinEng left a comment

Copy link
Copy Markdown
Contributor

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
Copy Markdown
CollaboratorAuthor

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:masterJan 7, 2020
@kainino0x
kainino0x deleted the nominal-types branch January 7, 2020 19:46
@darioncodarionco mentioned this pull request Mar 3, 2021
Sign up for freeto 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

@kainino0x@austinEng