`Phaser.Math.RND.Pick` and `Phaser.Math.RND.WeightedPick` should use `ArrayLike` interface
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 40.3k
- Forks
- 7.2k
- PR merge metrics
- No merged PRs in 30d
Description
Version
- Phaser Version: 3.90.0
- Operating system: Ubuntu 24.04 LTS (irrelevant)
Description
Currently, Phaser.Math.RandomDataGenerator.Pick and its weighted counterpart require the arguments passed in to be mutable arrays.
Since these functions do not mutate their arguments (and, moreover, do not require anything but numeric index support and a .length property), they should use the more general ArrayLike<T> interface instead.
At the moment, attempting to pass in readonly arrays or array-like objects such as TypedArray will produce type errors despite working perfectly well at runtime.
Example Test Code
import Phaser from "phaser";
const nums = [1, 2, 3] as const;
const randomNum = Phaser.Math.RND.pick(nums);
// type errors since `nums` is readonly, despite running perfectly fine
Additional Information
Trivial to fix; I will create a PR shortly.
Contributor 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.
Research direction
Start at the Phaser.Math.RandomDataGenerator.Pick and weighted-pick entry points named in the issue, then inspect their type definitions. Verify that readonly arrays and TypedArray-like inputs are accepted while preserving the existing runtime behavior; use the provided TypeScript example as the completion check.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- developer-experience
- Issue type
- Bug
- Difficulty
- 1/5
- Estimated time
- Under an hour
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 50/100