Type definition for TilemapLayer.getTileAt is wrong
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
- Tech stack
- javascript, typescript
- 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
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from phaserjs/phaser
-
Shader.preDestroy leaks its ShaderQuad's vertex buffer and VAO on every create/destroy cycle (4.2.1)Open
Difficulty 2/5 1-3 hours Newbie friendliness 86/100
Maintainers usually reply within 2 days
-
Difficulty 1/5 Under an hour Newbie friendliness 85/100
Maintainers usually reply within 2 days
-
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
Maintainers usually reply within 2 days
-
WebGL stroke of a Polygon drops a vertex when its origin-shifted position equals the previous raw vertexPossibly taken @ICOM725 claimed this 35 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
phaserjs/phaser#7361 · 1 comment ·
Maintainers usually reply within 2 days
-
MouseManager.stopListeners never removes the wheel listener — destroyed Game stays retained through the canvasPossibly taken @schulerj89 claimed this 75 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Maintainers usually reply within 2 days
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 66/100
druxt/umami.demo.druxtjs.org#527 ·
Maintainers usually reply within 9 days
-
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
NuSkooler/enigma-bbs#907 ·
Maintainers usually reply within 1 day
-
documentation good first issue
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
-
good first issue
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
-
documentation good first issue help wanted
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
Maintainers usually reply within 1 day