无论哪种情况:
document.getElementById('body');
// or
window.document.getElementById('body');
Run Code Online (Sandbox Code Playgroud)
我明白了 error TS2304: Cannot find name 'window'.
我错过了一些tsconfig.json我应该安装的定义文件吗?
运行时,我得到的消息tsc,并在vscode
tsconfig.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"
]
}
Run Code Online (Sandbox Code Playgroud)
我的答案:用于tsconfig.json我的目标es5和使用lib: ["es2015", "dom"]