phaserjs / phaserjs/phaser

Phaser event types should be literal types instead of `string`

Open
#7,248 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

🐛 TypeScript Bug
Dominant language
JavaScript
Stars
40.3k
Forks
7.2k
PR merge metrics
No merged PRs in 30d

Description

Version

  • Phaser Version: v3.90.0
  • Operating system: Ubuntu 24.04 LTS (irrelevant)

Description

The published .d.ts files for Phaser do not include the string names of various event constants.
This means external consumers using Phaser in a TypeScript project will see the types of PhaserCore..Events.BOOT as string, not the actual "boot" value that it assumes at runtime, making strongly typing event-related code effectively impossible.

Example Test Code

import Phaser from "phaser";

type bootEvt = typeof Phaser.Core.Events.BOOT;
//  ^  string, not "boot"

Additional Information

This can be easily fixed by changing the @type {string}s inside the module code to the actual value of their respective constants.

I might make a PR for this if I find the time; it is fairly easy and quick to fix (as well as something an end user cannot fix simply by overriding Phaser's typings)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the event module code, including src/core/events/BLUR_EVENT.js, and inspect the @type {string} declarations for the constants mentioned in the issue. Update the declarations so the published .d.ts types preserve each constant's literal runtime value, then verify that typeof Phaser.Core.Events.BOOT is "boot" in a TypeScript project.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, typescript
Domain
api, game-dev
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
58/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.