Fix types for pickRandom

The TS type for pickRandom currently restricts the given array to numbers, however (AFAIK) it doesn't actually care what the array given to it contains.

This PR:
- Uses a generic to type the given array
- Varies the return type (T or T[]) depending on the given args
This commit is contained in:
Matt Vague 2022-09-06 19:14:48 -07:00
parent dbfce94f7a
commit b2e83e6bd7

9
types/index.d.ts vendored
View File

@ -2203,11 +2203,10 @@ declare namespace math {
* undefined. Returns an array with the configured number of elements
* when number is > 1.
*/
pickRandom(
array: number[],
number?: number,
weights?: number[]
): number | number[]
pickRandom<T>(array: T[]): T
pickRandom<T>(array: T[], number: 1, weights?: number[]): T
pickRandom<T>(array: T[], number: number): T[]
pickRandom<T>(array: T[], number: number, weights: number[]): T[]
/**
* Return a random number larger or equal to min and smaller than max