【发布时间】:2017-05-11 05:12:23
【问题描述】:
对于任何一种情况:
document.getElementById('body');
// or
window.document.getElementById('body');
我收到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"
]
}
我的回答:
为了与tsconfig.json 一起使用,我以es5 为目标并使用lib: ["es2015", "dom"]
【问题讨论】:
-
你从哪里得到这个错误?在您的 IDE 中,还是在运行
tsc时?您当前的tsconfig.json文件是什么?如果您需要帮助,您需要提供更多相关信息 -
@NitzanTomer 我添加了您要求的信息。
标签: javascript typescript typescript2.0