无论哪种情况:
document.getElementById('body');
// or
window.document.getElementById('body');
我收到错误 TS2304:找不到名称“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"
]
}
我的回答:
为了与 tsconfig.json
一起使用,我以 es5
为目标并使用 lib: ["es2015", "dom"]
最佳答案
使用
"lib": ["dom"]
在 tsconfig.json 中
例如
{
"compilerOptions": {
"lib": ["es5", "es6", "dom"],
"outDir": "./dist/",
"sourceMap": true,
"noImplicitAny": true,
"module": "commonjs",
"target": "es6",
"moduleResolution": "node",
"jsx": "react"
},
"include": ["./src/**/*"]
}
关于javascript - typescript 找不到名称窗口或文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41336301/