最佳答案
无论哪种情况:
document.getElementById('body');
// or
window.document.getElementById('body');
我得到 error TS2304: Cannot find name 'window'.
对于应该安装的定义文件,我是否在 tsconfig.json中遗漏了什么?
我得到的消息时,运行 tsc和在 vscode
Json:
{
"compilerOptions": {
"allowJs": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"jsx": "react",
"module": "commonjs",
"moduleResolution": "node",
"noEmitOnError": true,
"noImplicitAny": false,
"sourceMap": true,
"suppressImplicitAnyIndexErrors": true,
"target": "ES2016",
"typeRoots": [
"node_modules/@types/",
"typings/index.d.ts"
]
},
"exclude": [
"node_modules",
"**/*-aot.ts"
]
}
我的回答:
与 tsconfig.json一起使用时,我的目标是 es5并使用 lib: ["es2015", "dom"]