Property 'getContext' does not exist on type 'HTMLElement'
Try this:
const canvas = document.getElementById('myChart') as HTMLCanvasElement;
const ctx = canvas.getContext('2d');
I would try:
const canvas = <HTMLCanvasElement> document.getElementById('myChart');
const ctx = canvas.getContext('2d');
the purpose of Typescript is to avoid wrong types. By default document.getElementById
returns a HTMLElement
type which is a generic type.
In order to make your app understand it is a canvas element you need to cast it using <CastedToType>
syntax.