Skip to content

Phaser.Math.RND.Pick and Phaser.Math.RND.WeightedPick should use ArrayLike interface #7257

@Bertie690

Description

@Bertie690

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[^1] (and, moreover, do not require anything but numeric indexes and a .length property), they should use the 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.

Image

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions