TypeScript: problems with type system

前端 未结 7 2437

I\'m just testing typescript in VisualStudio 2012 and have a problem with its type system. My html site has a canvas tag with the id \"mycanvas\". I\'m trying to draw a rect

7条回答
  •  孤城傲影
    2020-12-12 23:47

    var canvas =  document.getElementById("mycanvas");
    var ctx = canvas.getContext("2d");
    

    or using dynamic lookup with the any type (no typechecking):

    var canvas : any = document.getElementById("mycanvas");
    var ctx = canvas.getContext("2d");
    

    You can look at the different types in lib.d.ts.

提交回复
热议问题