Summary
HTMLCanvasElement.getContext("webgpu) and OffscreenCanvas.getContext("webgpu") are missing overloads and therefore resolving to the generic getContext overloads instead of returning GPUCanvasContext. GPUCanvasContext is already present in the generated DOM types. But additionalSignatures entries in inputfiles/overriding types.jsonc only include "2d", "bitmaprenderer", "webgl", "webgl2". As a result, WebGPU Canvas contexts losing it's type specific info.
Expected vs. Actual Behavior
Expected Behaviour
const canvas = document.createElement("canvas")
const context = canvas.getContext("webgpu")
context should be of type
GPUCanvasContext
Similarly for
const canvas = new OffscreenCanvas(300, 300)
const context = canvas.getContext("webgpu")
context should be of type
GPUCanvasContext
Actual Behaviour
const canvas = document.createElement("canvas")
const context = canvas.getContext("webgpu")
context is of type
RenderingContext
Similarly for
const canvas = new OffscreenCanvas(300, 300)
const context = canvas.getContext("webgpu")
context is of type
RenderingContext
because getContext("webgpu") falling back to generic overload
getContext(contexId: string, options?: any): RenderingContent | null;
This is preventing Typescript from recognising WebGPU-specific API's such as
context?.configure()
Playground Link
No response
Browser Support
Have Tried The Latest Releases
Additional Context
The relevant overloads are manually defined in inputfiles/overridingTypes.jsonc via additionalSignatures.
Currently additionalSignatures for:
- "2d"
- "bitmaprenderer"
- "webgl"
- "webgl2"
These are present for both HTMLCanvasElement and OffscreenCanvas, but webgpu is missing from the additionalSignatures.
Adding the following overload locally in lib.dom.d.ts resolves the issue:
getContext(context is: "webgpu"): GPUCanvasContext | null
Can I create a pull request adding missing "webgpu" overloads to these additionalSignatures entries in overridingTypes.jsonc file?
Summary
HTMLCanvasElement.getContext("webgpu) and OffscreenCanvas.getContext("webgpu") are missing overloads and therefore resolving to the generic getContext overloads instead of returning GPUCanvasContext. GPUCanvasContext is already present in the generated DOM types. But additionalSignatures entries in inputfiles/overriding types.jsonc only include "2d", "bitmaprenderer", "webgl", "webgl2". As a result, WebGPU Canvas contexts losing it's type specific info.
Expected vs. Actual Behavior
Expected Behaviour
context should be of type
GPUCanvasContextSimilarly for
context should be of type
GPUCanvasContextActual Behaviour
context is of type
RenderingContextSimilarly for
context is of type
RenderingContextbecause getContext("webgpu") falling back to generic overload
getContext(contexId: string, options?: any): RenderingContent | null;This is preventing Typescript from recognising WebGPU-specific API's such as
context?.configure()Playground Link
No response
Browser Support
Have Tried The Latest Releases
@types/web.Additional Context
The relevant overloads are manually defined in inputfiles/overridingTypes.jsonc via additionalSignatures.
Currently additionalSignatures for:
These are present for both HTMLCanvasElement and OffscreenCanvas, but webgpu is missing from the additionalSignatures.
Adding the following overload locally in lib.dom.d.ts resolves the issue:
getContext(context is: "webgpu"): GPUCanvasContext | null
Can I create a pull request adding missing "webgpu" overloads to these additionalSignatures entries in overridingTypes.jsonc file?