From ec4efba989c0a997ab55152697cbefbad160f562 Mon Sep 17 00:00:00 2001 From: Erica Clark Date: Wed, 19 Jan 2022 10:45:05 -0800 Subject: [PATCH] chore: add support for readonly arrays (#189) Co-authored-by: Shinigami --- src/helpers.ts | 2 +- src/random.ts | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/helpers.ts b/src/helpers.ts index f8219b3544d..c3a849d6a18 100644 --- a/src/helpers.ts +++ b/src/helpers.ts @@ -17,7 +17,7 @@ export class Helpers { * @method faker.helpers.randomize * @param array */ - randomize(array: T[] = ['a', 'b', 'c'] as unknown as T[]): T { + randomize(array: ReadonlyArray = ['a', 'b', 'c'] as unknown as ReadonlyArray): T { return this.faker.random.arrayElement(array); } diff --git a/src/random.ts b/src/random.ts index d460b4e36ca..8414134a84a 100644 --- a/src/random.ts +++ b/src/random.ts @@ -72,7 +72,7 @@ export class Random { * @method faker.random.arrayElement * @param array */ - arrayElement(array: T[] = ['a', 'b', 'c'] as unknown as T[]): T { + arrayElement(array: ReadonlyArray = ['a', 'b', 'c'] as unknown as ReadonlyArray): T { const r = this.faker.datatype.number({ max: array.length - 1 }); return array[r]; } @@ -85,7 +85,7 @@ export class Random { * @param count number of elements to pick */ arrayElements( - array: T[] = ['a', 'b', 'c'] as unknown as T[], + array: ReadonlyArray = ['a', 'b', 'c'] as unknown as ReadonlyArray, count?: number ): T[] { if (typeof count !== 'number') {