Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions cli/tsc/dts/lib.deno.unstable.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,11 @@ declare namespace Deno {
},
);

getContext(
contextId: "bitmaprenderer",
options?: any,
): ImageBitmapRenderingContext | null;
getContext(contextId: "webgpu", options?: any): GPUCanvasContext | null;
getContext(
contextId: OffscreenRenderingContextId,
options?: any,
Expand Down
2 changes: 2 additions & 0 deletions cli/tsc/dts/lib.deno_canvas.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,7 @@ interface GPUCanvasContext {
* @category Canvas */
declare var GPUCanvasContext: {
prototype: GPUCanvasContext;
new (): GPUCanvasContext;
};

/** A rendering context that displays the contents of an {@linkcode ImageBitmap}
Expand All @@ -275,6 +276,7 @@ interface ImageBitmapRenderingContext {
* @category Canvas */
declare var ImageBitmapRenderingContext: {
prototype: ImageBitmapRenderingContext;
new (): ImageBitmapRenderingContext;
};

/** A canvas that can be rendered to off the main thread and without being
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"args": "check main.ts",
"output": "main.out",
"exitCode": 0
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Check [WILDCARD]main.ts
22 changes: 22 additions & 0 deletions tests/specs/check/unsafe_window_surface_getcontext/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Type-level checks that Deno.UnsafeWindowSurface.getContext narrows per
// context id, mirroring the OffscreenCanvas.getContext overloads.

function assertType<T>(_value: T): void {}

declare const surface: Deno.UnsafeWindowSurface;

assertType<GPUCanvasContext | null>(surface.getContext("webgpu"));
assertType<ImageBitmapRenderingContext | null>(
surface.getContext("bitmaprenderer"),
);
declare const contextId: OffscreenRenderingContextId;
assertType<OffscreenRenderingContext | null>(surface.getContext(contextId));

// The constructor objects have construct signatures, so instanceof narrows.
declare const context: unknown;
if (context instanceof GPUCanvasContext) {
assertType<GPUCanvasContext>(context);
}
if (context instanceof ImageBitmapRenderingContext) {
assertType<ImageBitmapRenderingContext>(context);
}