-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Added strict types for WebGL and WebGL2 #21902
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
Conversation
type Float32List = (/* [AllowShared] */ Float32Array | sequence<GLfloat>); // WebIDL: ([AllowShared] Float32Array or sequence<GLfloat>) | ||
type Int32List = (/* [AllowShared] */ Int32Array | sequence<GLint>); // WebIDL: ([AllowShared] Int32Array or sequence<GLint>) | ||
// const GLenum (\w+)( +)= (\w+); --> readonly $1:$2GL_CONST<$3, '$1'>; | ||
declare namespace WebGLRenderingContextStrict { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Without Strict
, obviously, this is currently to avoid name conflicts with the existing declarations.
type DOMString = string | ||
|
||
type Nullable<T> = T | undefined | null | ||
type sequence<T> = T[] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nullable and sequence should probably be inlined.
We keep DOM related definitions in https://github.com/Microsoft/TSJS-lib-generator You can find more information about contributing lib.d.ts fixes at https://github.com/Microsoft/TSJS-lib-generator. For future references, please file an issue first to track changes. |
@mhegazy Yes, but considering the size of these types and the fact that there is very little overlap with the auto-generated version, specifying them as differences in The issue I linked above tracks what this solves as far as I can tell, and is marked as |
We really keep all the DOM lib definition and generation in one place. the reason is newer versions of the idl files have some of these types, and we get to remove some of the hand-authored ones as time goes on. |
I wrote some strict types for WebGL/WebGL2, if you want to add them to the core, it would fix #5855 among others.
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 (?).
I'd appreciate some feedback as to whether types likes this would be merged (they're NOT backwards-compatible for one) and if so, what changes would be necessary, before I put more effort into tests/correct generation of libs.