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

fixing WebGLRenderingContext type #63216

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 4 additions & 3 deletions types/gl/gl-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ import _default = require("gl");
const createContext = _default;
const WebGLRenderingContext = _default.WebGLRenderingContext;

createContext(0, 0); // $ExpectType WebGLRenderingContext
createContext(0, 0, { preserveDrawingBuffer: true }); // $ExpectType WebGLRenderingContext
createContext(0, 0); // $ExpectType WebGLRenderingContext & StackGLExtension
createContext(0, 0, { preserveDrawingBuffer: true }); // $ExpectType WebGLRenderingContext & StackGLExtension
createContext(0, 0).getExtension("STACKGL_resize_drawingbuffer"); // $ExpectType STACKGL_resize_drawingbuffer | null
createContext(0, 0).getExtension("STACKGL_destroy_context"); // $ExpectType STACKGL_destroy_context | null
createContext(0, 0).getExtension("STACKGL_resize_drawingbuffer")!.resize(0, 0); // $ExpectType void
createContext(0, 0).getExtension("STACKGL_destroy_context")!.destroy(); // $ExpectType void
new WebGLRenderingContext(); // $ExpectType WebGLRenderingContext
new WebGLRenderingContext(); // $ExpectType WebGLRenderingContext & StackGLExtension
WebGLRenderingContext.prototype; // $ExpectType WebGLRenderingContext & StackGLExtension
9 changes: 5 additions & 4 deletions types/gl/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
// Definitions by: DefinitelyTyped <https://github.com/DefinitelyTyped>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped

type WebGLRenderingContext = typeof window.WebGLRenderingContext & StackGLExtension;

interface StackGLExtension {
getExtension(extensionName: "STACKGL_resize_drawingbuffer"): STACKGL_resize_drawingbuffer | null;
getExtension(extensionName: "STACKGL_destroy_context"): STACKGL_destroy_context | null;
Expand All @@ -18,10 +16,13 @@ interface STACKGL_destroy_context {
destroy(): void;
}

declare function createContext(width: number, height: number, options?: WebGLContextAttributes): WebGLRenderingContext;
declare function createContext(width: number, height: number, options?: WebGLContextAttributes): WebGLRenderingContext & StackGLExtension;

declare namespace createContext {
const WebGLRenderingContext: WebGLRenderingContext;
const WebGLRenderingContext: WebGLRenderingContext & StackGLExtension & {
new(): WebGLRenderingContext & StackGLExtension;
prototype: WebGLRenderingContext & StackGLExtension;
};
}

export = createContext;