From 2e9ed960e3a11e4dcb78a434563fc04890c00c3d Mon Sep 17 00:00:00 2001 From: Shinigami Date: Thu, 4 May 2023 16:42:29 +0200 Subject: chore: rename generics (#2046) --- src/definitions/definitions.ts | 4 ++-- src/locale-proxy.ts | 16 ++++++++-------- src/modules/helpers/index.ts | 36 ++++++++++++++++++------------------ src/modules/helpers/unique.ts | 12 ++++++------ src/utils/types.ts | 18 +++++++++--------- 5 files changed, 43 insertions(+), 43 deletions(-) (limited to 'src') diff --git a/src/definitions/definitions.ts b/src/definitions/definitions.ts index 30f965c3..ca495e34 100644 --- a/src/definitions/definitions.ts +++ b/src/definitions/definitions.ts @@ -22,8 +22,8 @@ import type { WordDefinition } from './word'; /** * Wrapper type for all definition categories that will make all properties optional and allow extra properties. */ -export type LocaleEntry> = { - [P in keyof T]?: T[P] | null; +export type LocaleEntry> = { + [P in keyof TCategoryDefinition]?: TCategoryDefinition[P] | null; } & Record; // Unsupported & custom entries /** diff --git a/src/locale-proxy.ts b/src/locale-proxy.ts index a4dcc018..47b371d6 100644 --- a/src/locale-proxy.ts +++ b/src/locale-proxy.ts @@ -61,21 +61,21 @@ export function createLocaleProxy(locale: LocaleDefinition): LocaleProxy { * @param categoryData The module to create the proxy for. */ function createCategoryProxy< - CategoryData extends Record + TCategoryData extends Record >( categoryName: string, - categoryData: CategoryData = {} as CategoryData -): Required { + categoryData: TCategoryData = {} as TCategoryData +): Required { return new Proxy(categoryData, { - has(target: CategoryData, entryName: keyof CategoryData): boolean { + has(target: TCategoryData, entryName: keyof TCategoryData): boolean { const value = target[entryName]; return value != null; }, get( - target: CategoryData, - entryName: keyof CategoryData - ): CategoryData[keyof CategoryData] { + target: TCategoryData, + entryName: keyof TCategoryData + ): TCategoryData[keyof TCategoryData] { const value = target[entryName]; if (typeof entryName === 'symbol' || entryName === 'nodeType') { return value; @@ -97,5 +97,5 @@ function createCategoryProxy< set: throwReadOnlyError, deleteProperty: throwReadOnlyError, - }) as Required; + }) as Required; } diff --git a/src/modules/helpers/index.ts b/src/modules/helpers/index.ts index e6cf9075..3db15ca4 100644 --- a/src/modules/helpers/index.ts +++ b/src/modules/helpers/index.ts @@ -732,7 +732,7 @@ export class HelpersModule { /** * Returns the result of the callback if the probability check was successful, otherwise `undefined`. * - * @template T The type of result of the given callback. + * @template TResult The type of result of the given callback. * * @param callback The callback to that will be invoked if the probability check was successful. * @param options The options to use. Defaults to `{}`. @@ -745,8 +745,8 @@ export class HelpersModule { * * @since 6.3.0 */ - maybe( - callback: () => T, + maybe( + callback: () => TResult, options: { /** * The probability (`[0.00, 1.00]`) of the callback being invoked. @@ -755,7 +755,7 @@ export class HelpersModule { */ probability?: number; } = {} - ): T | undefined { + ): TResult | undefined { if (this.faker.datatype.boolean(options)) { return callback(); } @@ -990,7 +990,7 @@ export class HelpersModule { * * This does the same as `objectValue` except that it ignores (the values assigned to) the numeric keys added for TypeScript enums. * - * @template EnumType Type of generic enums, automatically inferred by TypeScript. + * @template T Type of generic enums, automatically inferred by TypeScript. * * @param enumObject Enum to pick the value from. * @@ -1006,11 +1006,11 @@ export class HelpersModule { * * @since 8.0.0 */ - enumValue>( - enumObject: EnumType - ): EnumType[keyof EnumType] { + enumValue>( + enumObject: T + ): T[keyof T] { // ignore numeric keys added by TypeScript - const keys: Array = Object.keys(enumObject).filter((key) => + const keys: Array = Object.keys(enumObject).filter((key) => isNaN(Number(key)) ); const randomKey = this.arrayElement(keys); @@ -1280,7 +1280,7 @@ export class HelpersModule { * Generates a unique result using the results of the given method. * Used unique entries will be stored internally and filtered from subsequent calls. * - * @template Method The type of the method to execute. + * @template TMethod The type of the method to execute. * * @param method The method used to generate the values. * @param args The arguments used to call the method. @@ -1304,14 +1304,14 @@ export class HelpersModule { * More info can be found in issue [faker-js/faker #1785](https://github.com/faker-js/faker/issues/1785). */ unique< - Method extends ( + TMethod extends ( // TODO @Shinigami92 2023-02-14: This `any` type can be fixed by anyone if they want to. // eslint-disable-next-line @typescript-eslint/no-explicit-any ...parameters: any[] ) => RecordKey >( - method: Method, - args: Parameters = [] as Parameters, + method: TMethod, + args: Parameters = [] as Parameters, options: { /** * This parameter does nothing. @@ -1358,7 +1358,7 @@ export class HelpersModule { */ store?: Record; } = {} - ): ReturnType { + ): ReturnType { deprecated({ deprecated: 'faker.helpers.unique', proposed: @@ -1387,7 +1387,7 @@ export class HelpersModule { /** * Generates an array containing values returned by the given method. * - * @template T The type of elements. + * @template TResult The type of elements. * * @param method The method used to generate the values. * @param options The optional options object. @@ -1399,8 +1399,8 @@ export class HelpersModule { * * @since 8.0.0 */ - multiple( - method: () => T, + multiple( + method: () => TResult, options: { /** * The number or range of elements to generate. @@ -1420,7 +1420,7 @@ export class HelpersModule { max: number; }; } = {} - ): T[] { + ): TResult[] { const count = this.rangeToNumber(options.count ?? 3); if (count <= 0) { return []; diff --git a/src/modules/helpers/unique.ts b/src/modules/helpers/unique.ts index 90896c64..d6bede7a 100644 --- a/src/modules/helpers/unique.ts +++ b/src/modules/helpers/unique.ts @@ -57,7 +57,7 @@ Try adjusting maxTime or maxRetries parameters for faker.helpers.unique().` * Generates a unique result using the results of the given method. * Used unique entries will be stored internally and filtered from subsequent calls. * - * @template Method The type of the method to execute. + * @template TMethod The type of the method to execute. * * @param method The method used to generate the values. * @param args The arguments used to call the method. @@ -71,14 +71,14 @@ Try adjusting maxTime or maxRetries parameters for faker.helpers.unique().` * @param options.store The store of unique entries. Defaults to `GLOBAL_UNIQUE_STORE`. */ export function exec< - Method extends ( + TMethod extends ( // TODO @Shinigami92 2023-02-14: This `any` type can be fixed by anyone if they want to. // eslint-disable-next-line @typescript-eslint/no-explicit-any ...parameters: any[] ) => RecordKey >( - method: Method, - args: Parameters, + method: TMethod, + args: Parameters, options: { startTime?: number; maxTime?: number; @@ -88,7 +88,7 @@ export function exec< compare?: (obj: Record, key: RecordKey) => 0 | -1; store?: Record; } = {} -): ReturnType { +): ReturnType { const now = new Date().getTime(); const { @@ -132,7 +132,7 @@ export function exec< } // Execute the provided method to find a potential satisfied value. - const result: ReturnType = method(...args) as ReturnType; + const result: ReturnType = method(...args) as ReturnType; // If the result has not been previously found, add it to the found array and return the value as it's unique. if (compare(store, result) === -1 && exclude.indexOf(result) === -1) { diff --git a/src/utils/types.ts b/src/utils/types.ts index 8c1bfe6b..c7aaf86c 100644 --- a/src/utils/types.ts +++ b/src/utils/types.ts @@ -3,9 +3,9 @@ * * @see https://github.com/microsoft/TypeScript/issues/29729#issuecomment-471566609 */ -export type LiteralUnion = - | T - | (U & { zz_IGNORE_ME?: never }); +export type LiteralUnion = + | TSuggested + | (TBase & { zz_IGNORE_ME?: never }); /** * A function that returns a value. @@ -22,18 +22,18 @@ export type Callable = ( /** * Type that represents a single method/function name of the given type. */ -export type MethodOf = { - [Key in keyof ObjectType]: ObjectType[Key] extends Signature +export type MethodOf = { + [Key in keyof TObjectType]: TObjectType[Key] extends TSignature ? Key extends string ? Key : never : never; -}[keyof ObjectType]; +}[keyof TObjectType]; /** * Type that represents all method/function names of the given type. */ export type MethodsOf< - ObjectType, - Signature extends Callable = Callable -> = ReadonlyArray>; + TObjectType, + TSignature extends Callable = Callable +> = ReadonlyArray>; -- cgit v1.2.3