Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

Type definition for TilemapLayer.getTileAt is wrong

Open Beginner friendly
#7,396 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 2 days

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
70/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Domain
game-dev

Research direction

The problem is the declared return type of getTileAt() on Phaser.Tilemaps.TilemapLayer, which says Phaser.Tilemaps.Tile but can return null when the x/y coordinates fall outside the layer. Find that method's type declaration and check whether the return type should include null. Done when the declaration matches the runtime behaviour and the reproduction code in the issue no longer compiles without a null check.

Written by the indexing model from the issue text.

Description

Version

  • Phaser Version: 4.2.1
  • Operating system: Linux
  • Browser: not relevant

Description

When using a Phaser.Tilemaps.TilemapLayer object, it exposes the method getTileAt(). The return type of that method according to the type definition is Phaser.Tilemaps.Tile. However, it could also return null if the given x/y coordinates are not within layer bounds.

Example Test Code

getTileId(tx:number, ty:number, layer: Phaser.Tilemaps.TilemapLayer): number {
  return layer.getTileAt(tx, ty).index ?? 0
}

The typescript compiler will happily accept this code but passing in values for tx and ty that are outside the layer boundaries will cause Cannot read properties of null (reading 'index') at runtime.

If I put an optional chaining operator (?) there, I would get the error Unnecessary optional chain on a non-nullish value and only if I manually type coerce it into as Phaser.Tilemaps.Tile | null the compiler does not complain.

Additional Information

Dominant language
JavaScript
Stars
40.4k
Forks
7.2k
PR merge metrics
No merged PRs in 30d

Getting set up

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.

More from phaserjs/phaser

All issues in phaserjs/phaser

Similar issues

More JavaScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.