Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

example of HTMLElement.addEventListener in typescript?

Tags:

typescript

can I get one? this is what I have, but I'm getting a red squiggly line:

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

below is my tsonconfig

{
    "compileOnSave": true,
    "compilerOptions": {
        "noImplicitAny": true,
        "removeComments": true,
        "sourceMap": false,
        "target": "es5",
        "lib": [
            "es6",
            "dom"
        ]
    },
    "include": [ "**/*" ]
}
like image 700
Mike_G Avatar asked Mar 14 '17 21:03

Mike_G


2 Answers

With your given tsconfig.json it compiles fine:

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

enter image description here

Your IDE is lying. Works fine in VSCode / alm 🌹

like image 62
basarat Avatar answered Oct 20 '22 09:10

basarat


The issue was ReSharper. I disabled the plugin and it worked fine. For reference I have attached two picutres, the first with ReSharper enabled, and the second with it disabled.resharpernoreshaper

like image 1
Mike_G Avatar answered Oct 20 '22 10:10

Mike_G