Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

Type definition for TilemapLayer.getTileAt is wrong

未关闭 适合新手
#7,396 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 2 天内回复

@hkbughk 已经在做这个了。

开始于 2026年10月12日。

  • #7398 来自 @hkbughk —— 未关闭

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
70/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
领域
game-dev

调研方向

问题在于 Phaser.Tilemaps.TilemapLayer 上 getTileAt() 声明的返回类型为 Phaser.Tilemaps.Tile,但当 x/y 坐标超出图层范围时,它可能返回 null。请找到该方法的类型声明,并检查返回类型是否应包含 null。当声明与运行时行为一致,且 issue 中的复现代码在没有 null 检查的情况下无法通过编译时,即完成。

由索引模型根据 Issue 内容生成。

描述

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

主要语言
JavaScript
星标
40.5k
派生
7.2k
PR 合并指标
30 天内没有已合并 PR

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

phaserjs/phaser 的其他 Issue

查看 phaserjs/phaser 的全部 Issue

相似的 Issue

更多 JavaScript Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。