Type definition for TilemapLayer.getTileAt is wrong
维护者通常 2 天内回复
评估
- 难度
- 2/5
- 预计耗时
- 1-3 小时
- 新手友好度
- 70/100
- Issue 类型
- 缺陷
- 描述清晰度
- 描述清楚
- 活跃度
- 活跃
- 技术栈
- javascript, typescript
- 领域
- 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
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
phaserjs/phaser 的其他 Issue
-
Shader.preDestroy leaks its ShaderQuad's vertex buffer and VAO on every create/destroy cycle (4.2.1)可能已有人在做 @k1epg01ng129-eng 于 3 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 86/100
维护者通常 2 天内回复
-
难度 1/5 1 小时以内 新手友好度 85/100
维护者通常 2 天内回复
-
难度 2/5 1-3 小时 新手友好度 75/100
维护者通常 2 天内回复
-
WebGL stroke of a Polygon drops a vertex when its origin-shifted position equals the previous raw vertex可能已有人在做 @ICOM725 于 42 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 84/100
phaserjs/phaser#7361 · 1 条评论 ·
维护者通常 2 天内回复
-
MouseManager.stopListeners never removes the wheel listener — destroyed Game stays retained through the canvas可能已有人在做 @schulerj89 于 82 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 78/100
维护者通常 2 天内回复
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 65/100
bigskysoftware/htmx#4147 ·
维护者通常 5 天内回复
-
难度 2/5 1-3 小时 新手友好度 62/100
vshymanskyy/StandWithUkraine#316 ·
-
bug/1-unconfirmed kind/bug
难度 2/5 1-3 小时 新手友好度 78/100
维护者通常 1 天内回复
-
难度 1/5 1 小时以内 新手友好度 74/100
521xueweihan/HelloGitHub#4010 · 2 条评论 ·
-
难度 1/5 1 小时以内 新手友好度 92/100