TypeScript
TypeScript copied to clipboard
lib.webworker.d.ts doesn't include canvas related types
lib Update Request
Configuration Check
My compilation target is ES2015 and my lib is webworker, es2019.
Missing / Incorrect Definition
Canvas-related types, such as CanvasState, are not present in lib.webworker.d.ts in any of the latest releases (4.5.5, 4.6.0-beta etc.). They are only present in lib.dom.d.ts.
This prevents the use of @types/offscreencanvas in webworker sources build.
Somehow confusingly, the missing types are there in your main and release-4.6 (in lib.webworker.d.ts), but not in actual releases in NPM.
Sample Code
Installing @types/offscreencanvas and using "types": ["offscreencanvas"]. No code is needed, because this will fail on its own if webworker lib is used (instead of dom).
Build failure:
Error: node_modules/@types/offscreencanvas/index.d.ts:14:53 - error TS2304: Cannot find name 'CanvasState'.
14 interface OffscreenCanvasRenderingContext2D extends CanvasState, CanvasTransform, CanvasCompositing,
~~~~~~~~~~~
Error: node_modules/@types/offscreencanvas/index.d.ts:14:66 - error TS2304: Cannot find name 'CanvasTransform'.
14 interface OffscreenCanvasRenderingContext2D extends CanvasState, CanvasTransform, CanvasCompositing,
~~~~~~~~~~~~~~~
Documentation Link
MDN specifically mentions that OffscreenCanvas is available in web workers.
This really is a blocker for anyone using webworkers in combination with offscreencanvas anywhere in the code.
Maybe fixed by #51300?
Is there a workaround for this?
This was fixed in #51300, yes.