diff options
| author | Shinigami <[email protected]> | 2023-05-04 16:42:29 +0200 |
|---|---|---|
| committer | GitHub <[email protected]> | 2023-05-04 16:42:29 +0200 |
| commit | 2e9ed960e3a11e4dcb78a434563fc04890c00c3d (patch) | |
| tree | 566aa44b9bb085b8a42c6f211b7ea93af4d8408f /src | |
| parent | 0740aa0da3b2ac1da4fd8a134d650162457552b4 (diff) | |
| download | faker-2e9ed960e3a11e4dcb78a434563fc04890c00c3d.tar.xz faker-2e9ed960e3a11e4dcb78a434563fc04890c00c3d.zip | |
chore: rename generics (#2046)
Diffstat (limited to 'src')
| -rw-r--r-- | src/definitions/definitions.ts | 4 | ||||
| -rw-r--r-- | src/locale-proxy.ts | 16 | ||||
| -rw-r--r-- | src/modules/helpers/index.ts | 36 | ||||
| -rw-r--r-- | src/modules/helpers/unique.ts | 12 | ||||
| -rw-r--r-- | src/utils/types.ts | 18 |
5 files changed, 43 insertions, 43 deletions
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<T extends Record<string, unknown>> = { - [P in keyof T]?: T[P] | null; +export type LocaleEntry<TCategoryDefinition extends Record<string, unknown>> = { + [P in keyof TCategoryDefinition]?: TCategoryDefinition[P] | null; } & Record<string, unknown>; // 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<string | symbol, unknown> + TCategoryData extends Record<string | symbol, unknown> >( categoryName: string, - categoryData: CategoryData = {} as CategoryData -): Required<CategoryData> { + categoryData: TCategoryData = {} as TCategoryData +): Required<TCategoryData> { 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<CategoryData>; + }) as Required<TCategoryData>; } 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<T>( - callback: () => T, + maybe<TResult>( + 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<EnumType extends Record<string | number, string | number>>( - enumObject: EnumType - ): EnumType[keyof EnumType] { + enumValue<T extends Record<string | number, string | number>>( + enumObject: T + ): T[keyof T] { // ignore numeric keys added by TypeScript - const keys: Array<keyof EnumType> = Object.keys(enumObject).filter((key) => + const keys: Array<keyof T> = 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<Method> = [] as Parameters<Method>, + method: TMethod, + args: Parameters<TMethod> = [] as Parameters<TMethod>, options: { /** * This parameter does nothing. @@ -1358,7 +1358,7 @@ export class HelpersModule { */ store?: Record<RecordKey, RecordKey>; } = {} - ): ReturnType<Method> { + ): ReturnType<TMethod> { 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<T>( - method: () => T, + multiple<TResult>( + 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>, + method: TMethod, + args: Parameters<TMethod>, options: { startTime?: number; maxTime?: number; @@ -88,7 +88,7 @@ export function exec< compare?: (obj: Record<RecordKey, RecordKey>, key: RecordKey) => 0 | -1; store?: Record<RecordKey, RecordKey>; } = {} -): ReturnType<Method> { +): ReturnType<TMethod> { 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> = method(...args) as ReturnType<Method>; + const result: ReturnType<TMethod> = method(...args) as ReturnType<TMethod>; // 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 extends U, U = string> = - | T - | (U & { zz_IGNORE_ME?: never }); +export type LiteralUnion<TSuggested extends TBase, TBase = string> = + | 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<ObjectType, Signature extends Callable = Callable> = { - [Key in keyof ObjectType]: ObjectType[Key] extends Signature +export type MethodOf<TObjectType, TSignature extends Callable = Callable> = { + [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<MethodOf<ObjectType, Signature>>; + TObjectType, + TSignature extends Callable = Callable +> = ReadonlyArray<MethodOf<TObjectType, TSignature>>; |
