TypeScript: problems with type system

前端 未结 7 2446

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:58

    This is an old topic... maybe dead to 2012, but exciting and new to VS Code and typescript.

    I had to do the following to get this to work in VS Code with the following package references.

    const demoCanvas: HTMLCanvasElement = document.getElementById('rfrnCanvas') as any;
    
            if(demoCanvas.getContext) {
                const context = demoCanvas.getContext('2d');
    
                if(context) {
                    reactangle(context);
                }
            }
    

    Typescript Version:

    {
        "@typescript-eslint/eslint-plugin": "^2.29.0",
        "@typescript-eslint/parser": "^2.29.0",
        "typescript": "^3.7.5"
    }
    
    

提交回复
热议问题