Typescript cannot find name window or document

前端 未结 2 1038
感动是毒
感动是毒 2020-12-01 17:48

For either case:

document.getElementById(\'body\');
// or
window.document.getElementById(\'body\');

I get error TS2304: Cannot find n

2条回答
  •  悲哀的现实
    2020-12-01 18:13

    use

    "lib": ["dom"]
    

    in tsconfig.json

    e.g.

    {
      "compilerOptions": {
        "lib": ["es5", "es6", "dom"],
        "outDir": "./dist/",
        "sourceMap": true,
        "noImplicitAny": true,
        "module": "commonjs",
        "target": "es6",
        "moduleResolution": "node",
        "jsx": "react"
      },
      "include": ["./src/**/*"]
    }
    

提交回复
热议问题