Skip to content

Constrain Structs.Map key types - #7377

Open
bagel786 wants to merge 1 commit into
phaserjs:masterfrom
bagel786:fix-map-typing
Open

Constrain Structs.Map key types#7377
bagel786 wants to merge 1 commit into
phaserjs:masterfrom
bagel786:fix-map-typing

Conversation

@bagel786

Copy link
Copy Markdown

Description

Tightens the typing of Phaser.Structs.Map (items 1-2 of #7323):

  • Constrains the K generic to string | number, so indexing the Map with an object or other unsafe-coercion keys is now a type error.
  • Removes the shadowing K/V generics from setAll (they disabled type safety entirely); elements is now typed as the nested-array pair form (K|V)[][], which is the closest jsdoc can get to the ideal [K, V][] tuple type until declarations support tuples.
  • The constructor's elements parameter is now actually optional in the types, matching its documented and runtime behavior.
  • get now includes undefined in its return type, matching its JSDoc.

Generated declarations were inspected (the Map class declaration now reads class Map<K extends string|number, V>, constructor(elements?: (K|V)[][], setAll(elements?: (K|V)[][]): this, get(key: K): V|undefined) but are not included in this PR because the current generator rewrites tens of thousands of unrelated lines.

Fixes #7323 (items 1 and 2)

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

Checklist:

  • I have run the pre-commit checks with pre-commit run --all-files (see CONTRIBUTING.md instructions to set it up)
  • I have run npm run ts and no errors are present.
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • I solved any possible warnings that npm run ts has generated that are related to my code to the best of my knowledge.
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

Copilot AI lite review requested due to automatic review settings September 11, 2026 22:00

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Phaser.Structs.Map has unsatisfactory and incorrect typing

2 participants