首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >如何显式声明某个Phaser类型的变量?

如何显式声明某个Phaser类型的变量?
EN

Stack Overflow用户
提问于 2018-08-05 02:15:50
回答 1查看 153关注 0票数 0

我尝试将PhaserBrunch一起使用,而TypeScript则使用sammebrunch-phaser2框架,但我遇到了TypeError

代码语言:javascript
复制
$ git clone https://github.com/samme/brunch-phaser2.git --branch typescript
$ cd brunch-phaser2
$ npm install
$ npm run start

> a-phaser-game@0.0.1 start /home/sam/github/samme/brunch-phaser2
> brunch watch --server

13:49:11 - info: application started on http://localhost:3333/
13:49:12 - error: Compiling of app/initialize.ts failed. TypeError: Cannot read property 'length' of undefined
Stack trace was suppressed. Run with `LOGGY_STACKS=1` to see the trace. 
13:49:12 - info: compiled 5 files into 2 files, copied 3 in 1.5 sec

当我将显式类型添加到我的game变量中时,my Phaser experimention repo中会出现一个略有不同的TypeError

代码语言:javascript
复制
$ git clone https://github.com/samestep/phaser-nonsense.git --branch type-error
$ cd phaser-nonsense
$ npm install
$ npm run start

> @ start /home/sam/github/samestep/phaser-nonsense
> brunch watch --server

13:56:42 - info: application started on http://localhost:3333/
13:56:42 - error: Compiling of app/initialize.ts failed. Error: Error 2503: Cannot find namespace 'Phaser'. (Line: 3, Col: 13)
Stack trace was suppressed. Run with `LOGGY_STACKS=1` to see the trace. 
13:56:42 - info: compiled 2 files into vendor.js, copied index.html in 1.3 sec

但不管是哪种情况,当我改变这一点时:

代码语言:javascript
复制
const game: Phaser.Game = new Phaser.Game({});

要这样做:

代码语言:javascript
复制
const game = new Phaser.Game({});

TypeError消失了。

为什么此显式类型声明会导致 TypeError错误发生,以及如何在不删除显式类型声明的情况下解决此错误?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-08-05 03:29:10

Brunch TypeScript插件不支持正确的引用解析(documentation)。他们的建议是将plugins: { brunchTypescript: { ignoreErrors: true } }添加到您的brunch-config.js中,并单独运行tsc --noEmit -p .来检查错误。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/51688398

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档