Skip to content

Commit

Permalink
chore: add support for readonly arrays (#189)
Browse files Browse the repository at this point in the history
Co-authored-by: Shinigami <[email protected]>
  • Loading branch information
clarkerican and Shinigami92 authored Jan 19, 2022
1 parent bd251ed commit ec4efba
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export class Helpers {
* @method faker.helpers.randomize
* @param array
*/
randomize<T = string>(array: T[] = ['a', 'b', 'c'] as unknown as T[]): T {
randomize<T = string>(array: ReadonlyArray<T> = ['a', 'b', 'c'] as unknown as ReadonlyArray<T>): T {
return this.faker.random.arrayElement(array);
}

Expand Down
4 changes: 2 additions & 2 deletions src/random.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export class Random {
* @method faker.random.arrayElement
* @param array
*/
arrayElement<T = string>(array: T[] = ['a', 'b', 'c'] as unknown as T[]): T {
arrayElement<T = string>(array: ReadonlyArray<T> = ['a', 'b', 'c'] as unknown as ReadonlyArray<T>): T {
const r = this.faker.datatype.number({ max: array.length - 1 });
return array[r];
}
Expand All @@ -85,7 +85,7 @@ export class Random {
* @param count number of elements to pick
*/
arrayElements<T>(
array: T[] = ['a', 'b', 'c'] as unknown as T[],
array: ReadonlyArray<T> = ['a', 'b', 'c'] as unknown as ReadonlyArray<T>,
count?: number
): T[] {
if (typeof count !== 'number') {
Expand Down

0 comments on commit ec4efba

Please sign in to comment.