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

More specific overloads for OffscreenCanvas.getContext #1480

Closed
jtbandes opened this issue Jan 21, 2023 · 1 comment
Closed

More specific overloads for OffscreenCanvas.getContext #1480

jtbandes opened this issue Jan 21, 2023 · 1 comment

Comments

@jtbandes
Copy link

I have a project which previously used @types/offscreencanvas for OffscreenCanvas support. That library defines separate overloads for the different getContext types:

https://github.com/DefinitelyTyped/DefinitelyTyped/blob/a6b57ed5f511b6d1c842b6acb4961c966d4afb00/types/offscreencanvas/index.d.ts#L46-L58

When pulling in the new changes via microsoft/TypeScript#51300 in TS 4.9.4, it seems like there's only one definition of getContext, so my calls to e.g. getContext("2d")?.clearRect(...) now fail to compile:

Property 'clearRect' does not exist on type 'CanvasRenderingContext2D | OffscreenRenderingContext'.
  Property 'clearRect' does not exist on type 'ImageBitmapRenderingContext'.ts(2339)

It would be nice to use the same approach of overloading based on the contextType parameter so that the proper types can be used without an as downcast.

@StenAL
Copy link
Contributor

StenAL commented Jan 21, 2023

I added these overloads in #1474, try using @types/web >= 0.0.88 for your DOM lib

jtbandes added a commit to foxglove/studio that referenced this issue Apr 6, 2023
**User-Facing Changes**
None

**Description**

- Bumps typescript to 5.0
- Removes some type hacks now that the builtin lib has better
OffscreenCanvas types (see
microsoft/TypeScript-DOM-lib-generator#1480)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants