From e10bca5ad0835e676c76c011f892c393e41426fb Mon Sep 17 00:00:00 2001 From: yassh Date: Thu, 24 Aug 2023 12:16:43 +0900 Subject: [PATCH] Add readonly array support to just-random --- packages/array-random/index.d.ts | 2 +- packages/array-random/index.tests.ts | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/array-random/index.d.ts b/packages/array-random/index.d.ts index e477b77b5..53d2ea7bf 100644 --- a/packages/array-random/index.d.ts +++ b/packages/array-random/index.d.ts @@ -1,3 +1,3 @@ declare function random(arr: [Head, ...Rest[]]): Head | Rest; -declare function random(arr: T[]): T | undefined; +declare function random(arr: readonly T[]): T | undefined; export default random; diff --git a/packages/array-random/index.tests.ts b/packages/array-random/index.tests.ts index 5b02d6ca5..e6871b794 100644 --- a/packages/array-random/index.tests.ts +++ b/packages/array-random/index.tests.ts @@ -7,6 +7,8 @@ const test3: number = random([1, 2, 3]); const test4: number | string = random([1, 2, "a"]); const numbers: number[] = []; const test5: number | undefined = random(numbers); +const readonlyNumbers: readonly number[] = [1, 2, 3]; +const test6: number | undefined = random(readonlyNumbers); // Not OK // @ts-expect-error