From 31383aaf27f0b3e54ec504a9c68f051e3b2f83b6 Mon Sep 17 00:00:00 2001 From: PavelTheCoder Date: Fri, 9 Aug 2024 13:38:16 +0200 Subject: [PATCH] Use generic types for choice and shuffle methods --- @types/PRNG.d.ts | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/@types/PRNG.d.ts b/@types/PRNG.d.ts index bfb31f4..d77f915 100644 --- a/@types/PRNG.d.ts +++ b/@types/PRNG.d.ts @@ -177,10 +177,11 @@ declare class PRNG { * random.choice(arr); // 4 * * @public - * @param {any[]} array -> Array of any type from which we randomly select one item. - * @returns {any} A single item from the array of type ?. + * @template T + * @param {T[]} array -> Array of any type from which we randomly select one item. + * @returns {T} A single item from the array of type ?. */ - public choice(array: any[]): any; + public choice(array: T[]): T; /** * Randomly shuffles the given array using the fisher-yates algorithm. * @@ -200,11 +201,12 @@ declare class PRNG { * console.log(shuffled); // [4, 2, 3, 1] * * @public - * @param {any[]} array -> Array of any type to be shuffled. + * @template T + * @param {T[]} array -> Array of any type to be shuffled. * @param {boolean} inPlace -> Shuffle the array (true) or shuffle a copy of array (false). - * @returns {any[]} Array shuffled (inPlace === false), shuffled copy of array (inPlace === true). + * @returns {T[]} Array shuffled (inPlace === false), shuffled copy of array (inPlace === true). */ - public shuffle(array: any[], inPlace?: boolean): any[]; + public shuffle(array: T[], inPlace?: boolean): T[]; /** * Creates an array of the given size populated with the result of the mapFn. *