20
7

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

typescript getContext()でエラー

Last updated at Posted at 2016-07-31

TypeScriptでChartjsをしていたのだけど、下記のソースで Property 'getContext' does not exist on type 'HTMLElement'.と怒られてしまった。

修正前.ts
var ctx = <HTMLCanvasElement> document.getElementById('lineChartCanvas').getContext("2d");

下記に修正することで解決

修正後.ts
var canvas = <HTMLCanvasElement> document.getElementById('lineChartCanvas');
var ctx = canvas.getContext("2d");

[参考url]
http://stackoverflow.com/questions/13669404/typescript-problems-with-type-system

20
7
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
20
7

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?