【发布时间】:2017-08-14 10:59:27
【问题描述】:
在我的 Meteor/React 项目中,我有以下行:
let gameId = window.prompt("Please enter the ID of the game you wish to load.");
TypeScript 给出了转译错误Cannot find name 'window'。
我正在使用barbatus/typescript,带有默认编译器选项:
{
"module": "commonjs",
"target": "es5",
"moduleResolution": "node",
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"sourceMap": true
}
我尝试在我的 Meteor 项目的根目录中创建一个 tsconfig.json,复制上述编译器选项但附加以下行:
"lib": ["es2015",
"dom"]
但是,错误仍然存在。
【问题讨论】:
-
请将您的
tsconfig.json添加到您的问题中,即使它在链接中 -
你的
tsconfig.json必须有“dom” -
添加“declare var window: any;”后可以试试吗在你的代码中
-
您确定在 tsconfig.json 中将
compilerOptions添加为compilerOptions属性,而不是根 json。
标签: javascript typescript meteor