Я пытаюсь использовать Phaser с Бранч и Машинопись, используя скелет samme
brunch-phaser2
, но я сталкиваюсь с TypeError
:
$ 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
уходит.
Почему это явное объявление типа вызывает возникновение TypeError
и как я могу устранить ошибку, не удаляя явное объявление типа?
Плагин Brunch TypeScript не поддерживает правильное разрешение ссылок (документация). Они рекомендуют добавить plugins: { brunchTypescript: { ignoreErrors: true } }
к вашему brunch-config.js
и отдельно запустить tsc --noEmit -p .
для проверки ошибок.