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

山姆·埃斯特普(Sam Estep)

我正在尝试使用框架PhaserBrunchTypeScript一起使用,但是我遇到了sammebrunch-phaser2TypeError

$ git clone https://github.com/samme/brunch-phaser2.git --branch typescript
$ cd brunch-phaser2
$ npm install
$ npm run start

> [email protected] 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

当我向变量添加显式类型时TypeError我的Phaser实验存储库中会出现一个略有不同的内容game

$ 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

但是无论哪种情况,当我更改此设置时:

const game: Phaser.Game = new Phaser.Game({});

对此:

const game = new Phaser.Game({});

TypeError消失。

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

马特·麦考森

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

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

显式变量声明

使用New-Variable函数创建变量时如何显式声明变量的类型?

Groovy和IntelliJ:如何使用显式类型声明提取变量?

PostgreSQL用显式数据类型声明变量

Ocaml - 如何显式声明列表可变类型

使用extract()时的显式变量声明

是否可以在PHP中显式声明局部变量的类型?

NgRx:如何声明动作创建者创建的动作的显式类型?

显式声明嵌套类型的用户定义类型

Typescript中的类型推断与显式类型声明

如何显式转换类型为“对象”的变量以满足多类型通用约束?

在razor视图引擎中使用var关键字作为变量,而不是使用显式数据类型进行声明

为什么必须显式声明嵌套类型?

声明具有显式类型node.js的字典

如何显式类型转换指针

如何声明循环变量的类型

如何声明不是变量的类型

如何显式声明cv :: Mat类型作为OpenCV库函数的一部分

如何解决“断言要求呼叫目标中的每个名称都使用显式类型批注.ts(2775)声明”?

如何在Gradle Android中添加显式声明

解决隐式时,Scala如何使用显式类型?

如何检查类型是否显式/隐式可构造?

如何显式地将某些模板输入作为参数?

显式类型参数

显式类型转换?

显式Polyfit与变量

在隐式工作时,在Go var声明中显式提供类型失败

打开任何类型的Android文件,而无需显式声明MIME类型

为什么F#有两种类型的显式类型声明?