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.
Version
Description
Currently,
Phaser.Math.RandomDataGenerator.Pickand 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
.lengthproperty), they should use the more generalArrayLike<T>interface instead.At the moment, attempting to pass in
readonlyarrays or array-like objects such asTypedArraywill produce type errors despite working perfectly well at runtime.Example Test Code
Additional Information
Trivial to fix; I will create a PR shortly.