Chartjs-Angular Chartjs error TS2304: Cannot find name OffscreenCanvasRenderingContext2D

2๐Ÿ‘

I hope I can still help you and other people with this problem.

The OffscreenCanvas error is created because it is an experimental technology as stated in here.

Therefore it is probable that errors, bugs, glitch, among others are created.
My suggestion from my own experience is in node_modules/chart.js/types/index.esm.d.ts(500):

export declare type ChartItem =
  | string
  | CanvasRenderingContext2D
  // | OffscreenCanvasRenderingContext2D
  | HTMLCanvasElement
  // | OffscreenCanvas
  | { canvas: HTMLCanvasElement}// | OffscreenCanvas }
  | ArrayLike<CanvasRenderingContext2D | HTMLCanvasElement>;// | OffscreenCanvas>;

In the case of what happens with DeepPartial in my case what I did in node_modules / chart.js / types / utils.d.ts (13 and 14):

13  type _DeepPartialArray<T> = Array<Partial<T>>
14  type _DeepPartialObject<T> = { [P in keyof T]?: Partial<T[P]> };

what I did was change

Array<DeepPartial<T>>

to

Array<Partial<T>>

and

{[P in keyof T] ?: DeepPartial<T[P]>}

to

{[P in keyof T] ?: Partial<T[P]>}

Since a circular reference is being created with DeepPartial and that usually gives an error, my reference for this is in another language, but I will share it with you anyway

https://www.youtube.com/watch?v=aMfvQLLqbzE&ab_channel=makigas%3Atutorialesdeprogramaci%C3%B3n

Iโ€™m using chart.js to create some charts with the MEAN Stack, it generated problems for me more than anything in compilation because the charts and the application still worked.

This is while a real solution comes out, since I have researched for almost a week and your question is the most accurate I have found on the entire internet that has exactly the same error, but still has no answer, I suppose because it is something very recent and that has not yet affected the mass, a true solution or correction of these errors has not come out.

Greetings!

0๐Ÿ‘

Trying installing this as a dev dependency in your angular application

npm i @types/offscreencanvas --save-dev

Leave a comment