TypeScript icon indicating copy to clipboard operation
TypeScript copied to clipboard

lib.webworker.d.ts doesn't include canvas related types

Open LubosD opened this issue 3 years ago • 1 comments

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.

LubosD avatar Feb 06 '22 17:02 LubosD

This really is a blocker for anyone using webworkers in combination with offscreencanvas anywhere in the code.

Josef-Haupt avatar Nov 29 '22 13:11 Josef-Haupt

Maybe fixed by #51300?

jtbandes avatar Jan 21 '23 01:01 jtbandes

Is there a workaround for this?

Swoorup avatar Apr 21 '23 12:04 Swoorup

This was fixed in #51300, yes.

jakebailey avatar Jul 09 '23 22:07 jakebailey