Skip to content

Strict types for WebGL and WebGL2 #373

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

Open
NaridaL opened this issue Feb 12, 2018 · 2 comments
Open

Strict types for WebGL and WebGL2 #373

NaridaL opened this issue Feb 12, 2018 · 2 comments

Comments

@NaridaL
Copy link

NaridaL commented Feb 12, 2018

Opening a new issue, as requested. See also microsoft/TypeScript#21902.

I wrote some strict types for WebGL/WebGL2, which would fix microsoft/TypeScript#5855 among others. See https://github.com/Microsoft/TypeScript/pull/21902/files.

The auto-generated typings would need to be excluded. Maybe this should be added as a separate option for the lib compiler option as it's not exactly lightweight.

I might have made some of the types too strict, for example for texImage2D I added overloads which exactly match the internalFormat/format/type combinations allowed by the WebGL spec. When calling the function with immediate values, this is fine, but calling it with values in variables is going to require as any casts. (Which could be fine, as at that point you're responsible for the correct types anyway).

Also the following would fail, because TS doesn't currently generate a common supertype (?).

declare const randomParameter: GL['ACTIVE_TEXTURE'] | GL['ALIASED_LINE_WIDTH_RANGE']
const x = gl.getParameter(randomParameter)
// no matching overload, but a return type of GL.TextureUnits | Float32Array would make sense.

Is adding the .d.ts files as additional inputFiles which are concatenated to the dom.generated.d.ts (or a separate webgl lib file) an option? I added a number of subtypes which are only implicitly in the spec: all constants are typed as a generic GLenum in spec, although there are many different subgroups which I typed explicitly. It is highly unlikely that those will be added to the IDL.

@brhumphe
Copy link

What options are there to start using this in projects in lieu of the definitions in the stock lib.d.ts?

@NaridaL
Copy link
Author

NaridaL commented Apr 18, 2018

@brhumphe https://github.com/NaridaL/webgl-strict-types

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

No branches or pull requests

2 participants