打字稿中的HTMLElement.addEventListener示例?

时间:2017-03-14 21:10:50

标签: typescript

我可以买一个吗?这就是我所拥有的,但我得到了一条红色的波浪线:

let button = <HTMLElement>document.body.querySelector(".btn");
button.addEventListener("click", () =>{});//not sure what to do here.  I know its wrong though.

下面是我的tsonconfig

{
    "compileOnSave": true,
    "compilerOptions": {
        "noImplicitAny": true,
        "removeComments": true,
        "sourceMap": false,
        "target": "es5",
        "lib": [
            "es6",
            "dom"
        ]
    },
    "include": [ "**/*" ]
}

2 个答案:

答案 0 :(得分:4)

使用你给定的tsconfig.json编译好了:

let button = <HTMLElement>document.body.querySelector(".btn");
button.addEventListener("click", () => { });

enter image description here

你的IDE在说谎。在VSCode / alm中正常工作

答案 1 :(得分:1)

问题是ReSharper。我禁用了该插件,它工作正常。作为参考,我附加了两个picutres,第一个启用了ReSharper,第二个启用了它。resharper noreshaper