chartjs / Chart.js

Simple HTML5 Charts using the <canvas> tag
https://www.chartjs.org/
MIT License
64.5k stars 11.89k forks source link

errors with typescript 4.4 #9594

Closed jacekkarczmarczyk closed 3 years ago

jacekkarczmarczyk commented 3 years ago

Expected Behavior

no compilation errors

Current Behavior

ERROR in C:/cygwin64/home/PC/XXX/web/node_modules/chart.js/types/index.esm.d.ts(540,5):
540:5 Cannot find name 'OffscreenCanvasRenderingContext2D'.
    538 |   | string
    539 |   | CanvasRenderingContext2D
  > 540 |   | OffscreenCanvasRenderingContext2D
        |     ^
    541 |   | HTMLCanvasElement
    542 |   | OffscreenCanvas
    543 |   | { canvas: HTMLCanvasElement | OffscreenCanvas }
ERROR in C:/cygwin64/home/PC/XXX/web/node_modules/chart.js/types/index.esm.d.ts(542,5):
542:5 Cannot find name 'OffscreenCanvas'.
    540 |   | OffscreenCanvasRenderingContext2D
    541 |   | HTMLCanvasElement
  > 542 |   | OffscreenCanvas
        |     ^
    543 |   | { canvas: HTMLCanvasElement | OffscreenCanvas }
    544 |   | ArrayLike<CanvasRenderingContext2D | HTMLCanvasElement | OffscreenCanvas>;
    545 |
ERROR in C:/cygwin64/home/PC/XXX/web/node_modules/chart.js/types/index.esm.d.ts(543,35):
543:35 Cannot find name 'OffscreenCanvas'.
    541 |   | HTMLCanvasElement
    542 |   | OffscreenCanvas
  > 543 |   | { canvas: HTMLCanvasElement | OffscreenCanvas }
        |                                   ^
    544 |   | ArrayLike<CanvasRenderingContext2D | HTMLCanvasElement | OffscreenCanvas>;
    545 |
    546 | export declare enum UpdateModeEnum {
ERROR in C:/cygwin64/home/PC/XXX/web/node_modules/chart.js/types/index.esm.d.ts(544,62):
544:62 Cannot find name 'OffscreenCanvas'.
    542 |   | OffscreenCanvas
    543 |   | { canvas: HTMLCanvasElement | OffscreenCanvas }
  > 544 |   | ArrayLike<CanvasRenderingContext2D | HTMLCanvasElement | OffscreenCanvas>;
        |                                                              ^
    545 |
    546 | export declare enum UpdateModeEnum {
    547 |   resize = 'resize',
Version: typescript 4.4.2

Possible Solution

add @types/offscreencanvas maybe?

Steps to Reproduce

create a project with chart.js and typescript 4.4

Environment

ryanhuff commented 3 years ago

I'm seeing this too. Any workarounds you've found?

IceSentry commented 3 years ago

Right now, I simply disabled typechecking of external libraries. It's far from ideal, but at least I can still compile and run my code

etimberg commented 3 years ago

This was likely caused by https://github.com/microsoft/TypeScript/pull/44684 which seems to have removed the OffscreenCanvasRenderingContext2D and OffscreenCanvas types because they're only available in Chrome.

etimberg commented 3 years ago

Was resolved in #9617