-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
HTMLCanvasElement.getContext() missing "webgl" type in lib.d.ts #5773
Comments
PRs are welcomed. here is some details on adding these type definitions: https://github.com/Microsoft/TypeScript/blob/master/CONTRIBUTING.md#contributing-libdts-fixes |
Hi, I am fairly new to TypeScript and OSS, and this looks like a great way for me to start!
Let me know how you guys feel about that. |
I would split into two signatures, one for "webgl" | "experimental-webgl" and another for "webgl2" | "experimental-webgl2" since they return two different types. this way the user does not have to check/cast the result. |
right, makes sense, I'll get started on this then :) |
My initial proposal was trying to be simple while still describing the overload signatures correctly. getContext(contextType: "2d", contextAttributes?: {
alpha?: boolean; willReadFrequently?: boolean; storage?: string;
[attrib: string]: boolean | string; }): CanvasRenderingContext2D;
getContext(contextType: "webgl" | "experimental-webgl", contextAttributes?: {
alpha?: boolean; depth?: boolean; stencil?: boolean; antialias?: boolean;
premultipliedAlpha?: boolean; preserveDrawingBuffer?: boolean; failIfMajorPerformanceCaveat?: boolean;
[attrib: string]: boolean; }): WebGLRenderingContext;
getContext(contextType: "webgl2" | "experimental-webgl2", contextAttributes?: {
alpha?: boolean; depth?: boolean; stencil?: boolean; antialias?: boolean;
premultipliedAlpha?: boolean; preserveDrawingBuffer?: boolean; failIfMajorPerformanceCaveat?: boolean;
[attrib: string]: boolean; }): WebGL2RenderingContext;
getContext(contextType: string, contextAttributes?: { [prop: string]: boolean | string; }):
CanvasRenderingContext2D | WebGLRenderingContext | WebGL2RenderingContext; And maybe in order to shorten the WebGL overloads, how about creating some interface WebGLAttributesObj {
alpha?: boolean;
depth?: boolean;
stencil?: boolean;
antialias?: boolean;
premultipliedAlpha?: boolean;
preserveDrawingBuffer?: boolean;
failIfMajorPerformanceCaveat?: boolean;
[attrib: string]: boolean;
}
getContext(contextType: "webgl" | "experimental-webgl", contextAttributes?: WebGLAttributesObj): WebGLRenderingContext;
getContext(contextType: "webgl2" | "experimental-webgl2", contextAttributes?: WebGLAttributesObj): WebGL2RenderingContext; P.S.: In order to have WebGL2RenderingContext type, we're gonna need some stub for it as well: interface WebGL2RenderingContext extends WebGLRenderingContext {} |
The re-proposal looks good. |
If or when that happens, it's as simple as making another interface extending that. |
@GoToLoop sounds good, I guess I will ignore the webgl2 stuff for now then, but still use an interface for the webgl context,
But the dom.generated.d.ts is not updating the existing interface... does it need to go into overridingTypes.json instead? I have tried that as well.. doesn't work either. |
Sorry for the delay. @zhengbli can you help @rohitverma007 out. |
@rohitverma007 You did the right thing to add the content in |
@rohitverma007 the script has been updated. Can you try with the new content in |
Overloaded
getContext(contextId: "experimental-webgl"): WebGLRenderingContext;
is missing "webgl" according to these reference sites below:https://developer.Mozilla.org/en-US/docs/Web/API/HTMLCanvasElement/getContext
http://www.JavaScripture.com/HTMLCanvasElement
Also all the overloaded methods got an optional
contextAttributes?: {}
parameter.And I don't think
...args: any[]
represents the 2nd parameter correctly.This is my change proposal for them btW: :-D
The text was updated successfully, but these errors were encountered: