From b2e83e6bd7780d42e3717f86bf9bd713fc4e8127 Mon Sep 17 00:00:00 2001 From: Matt Vague Date: Tue, 6 Sep 2022 19:14:48 -0700 Subject: [PATCH] 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 --- types/index.d.ts | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/types/index.d.ts b/types/index.d.ts index 0b969ecc0..27eaeff0a 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -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(array: T[]): T + pickRandom(array: T[], number: 1, weights?: number[]): T + pickRandom(array: T[], number: number): T[] + pickRandom(array: T[], number: number, weights: number[]): T[] /** * Return a random number larger or equal to min and smaller than max