【问题标题】:TypeScript Cannot find name 'window'TypeScript 找不到名称“窗口”
【发布时间】: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


【解决方案1】:

我在tsconfig.json的lib compilerOptions中添加了“dom”,然后这个问题就解决了。

【讨论】:

  • 您的答案可以通过额外的支持信息得到改进。请edit 添加更多详细信息,例如引用或文档,以便其他人可以确认您的答案是正确的。你可以找到更多关于如何写好答案的信息in the help center
  • 虽然此链接可能会回答问题,但最好在此处包含答案的基本部分并提供链接以供参考。如果链接页面发生更改,仅链接答案可能会失效。 - From Review
猜你喜欢
  • 2019-07-23
  • 2016-05-23
  • 1970-01-01
  • 2016-11-05
  • 2018-08-29
  • 1970-01-01
  • 2016-01-24
  • 2017-05-11
相关资源
最近更新 更多