From b071d42431299b8c1829060fb36cc7443a6c1f23 Mon Sep 17 00:00:00 2001 From: ST-DDT Date: Thu, 27 Apr 2023 00:01:10 +0200 Subject: [PATCH 1/3] fix(types): locale proxy --- src/locale-proxy.ts | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/locale-proxy.ts b/src/locale-proxy.ts index ae5ede1757a..848b4665758 100644 --- a/src/locale-proxy.ts +++ b/src/locale-proxy.ts @@ -5,11 +5,15 @@ import { FakerError } from './errors/faker-error'; * A proxy for LocaleDefinitions that marks all properties as required and throws an error when an entry is accessed that is not defined. */ export type LocaleProxy = Readonly<{ - [key in keyof LocaleDefinition]-?: Readonly< - Required> - >; + [key in keyof LocaleDefinition]-?: LocaleProxyCategory; }>; +type LocaleProxyCategory = Readonly<{ + [key in keyof T]-?: LocaleProxyEntry; +}>; + +type LocaleProxyEntry = unknown extends T ? T : Readonly>; + const throwReadOnlyError: () => never = () => { throw new FakerError('You cannot edit the locale data on the faker instance'); }; From e3984161e1b5fc1a704416faa6c241a7379a7175 Mon Sep 17 00:00:00 2001 From: ST-DDT Date: Thu, 27 Apr 2023 00:26:09 +0200 Subject: [PATCH 2/3] fix: more param type fixes --- src/modules/helpers/index.ts | 13 ++++++++----- src/modules/word/filterWordListByLength.ts | 10 +++++----- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/src/modules/helpers/index.ts b/src/modules/helpers/index.ts index 0bb54fb631a..fd34a7344d6 100644 --- a/src/modules/helpers/index.ts +++ b/src/modules/helpers/index.ts @@ -1078,7 +1078,7 @@ export class HelpersModule { * * @since 8.0.0 */ - fake(patterns: string[]): string; + fake(patterns: ReadonlyArray): string; /** * Generator for combining faker methods based on a static string input or an array of static string inputs. * @@ -1127,10 +1127,13 @@ export class HelpersModule { * * @since 7.4.0 */ - fake(pattern: string | string[]): string; - fake(pattern: string | string[]): string { - if (Array.isArray(pattern)) { - pattern = this.arrayElement(pattern); + fake(pattern: string | ReadonlyArray): string; + fake(pattern_: string | ReadonlyArray): string { + let pattern: string; + if (Array.isArray(pattern_)) { + pattern = this.arrayElement(pattern_); + } else { + pattern = pattern_ as string; } // find first matching {{ and }} diff --git a/src/modules/word/filterWordListByLength.ts b/src/modules/word/filterWordListByLength.ts index 4651d4973ef..e866bb9ecbf 100644 --- a/src/modules/word/filterWordListByLength.ts +++ b/src/modules/word/filterWordListByLength.ts @@ -10,7 +10,7 @@ const STRATEGIES = { throw new FakerError('No words found that match the given length.'); }, closest: ( - wordList: string[], + wordList: ReadonlyArray, length: { min: number; max: number } ): string[] => { const wordsByLength = wordList.reduce((data, word) => { @@ -30,15 +30,15 @@ const STRATEGIES = { word.length === length.max + closestOffset ); }, - shortest: (wordList: string[]): string[] => { + shortest: (wordList: ReadonlyArray): string[] => { const minLength = Math.min(...wordList.map((word) => word.length)); return wordList.filter((word) => word.length === minLength); }, - longest: (wordList: string[]): string[] => { + longest: (wordList: ReadonlyArray): string[] => { const maxLength = Math.max(...wordList.map((word) => word.length)); return wordList.filter((word) => word.length === maxLength); }, - 'any-length': (wordList: string[]): string[] => { + 'any-length': (wordList: ReadonlyArray): string[] => { return [...wordList]; }, } as const; /* @@ -67,7 +67,7 @@ string, // Parameters[0]['strategy'] * - `any-length`: Returns a copy of the original word list. */ export function filterWordListByLength(options: { - wordList: string[]; + wordList: ReadonlyArray; length?: number | { min: number; max: number }; strategy?: 'fail' | 'closest' | 'shortest' | 'longest' | 'any-length'; }): string[] { From 0f25ef80169512ea1d1fa169876035bae5e847b2 Mon Sep 17 00:00:00 2001 From: Shinigami92 Date: Thu, 27 Apr 2023 21:01:08 +0200 Subject: [PATCH 3/3] turnaroundthecheck --- src/modules/helpers/index.ts | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/modules/helpers/index.ts b/src/modules/helpers/index.ts index fd34a7344d6..cdc6104183c 100644 --- a/src/modules/helpers/index.ts +++ b/src/modules/helpers/index.ts @@ -1128,13 +1128,9 @@ export class HelpersModule { * @since 7.4.0 */ fake(pattern: string | ReadonlyArray): string; - fake(pattern_: string | ReadonlyArray): string { - let pattern: string; - if (Array.isArray(pattern_)) { - pattern = this.arrayElement(pattern_); - } else { - pattern = pattern_ as string; - } + fake(pattern: string | ReadonlyArray): string { + pattern = + typeof pattern === 'string' ? pattern : this.arrayElement(pattern); // find first matching {{ and }} const start = pattern.search(/{{[a-z]/);