diff options
| author | DivisionByZero <[email protected]> | 2024-09-26 17:50:05 +0200 |
|---|---|---|
| committer | GitHub <[email protected]> | 2024-09-26 17:50:05 +0200 |
| commit | 9537dfddba882bd93d9a429697fd44bc72428426 (patch) | |
| tree | f60b5b694d5e4e8ddab228aeb20c7b7746685edc /src/internal/types.ts | |
| parent | 424b120a4d94b15b6e77c04a0aaffd0016a9c870 (diff) | |
| download | faker-9537dfddba882bd93d9a429697fd44bc72428426.tar.xz faker-9537dfddba882bd93d9a429697fd44bc72428426.zip | |
infra: update file structure for util/internal (#3141)
Diffstat (limited to 'src/internal/types.ts')
| -rw-r--r-- | src/internal/types.ts | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/src/internal/types.ts b/src/internal/types.ts new file mode 100644 index 00000000..affdda7e --- /dev/null +++ b/src/internal/types.ts @@ -0,0 +1,39 @@ +/** + * Type that provides auto-suggestions but also any string. + * + * @see https://github.com/microsoft/TypeScript/issues/29729#issuecomment-471566609 + */ +export type LiteralUnion<TSuggested extends TBase, TBase = string> = + | TSuggested + | (TBase & { zz_IGNORE_ME?: never }); + +/** + * A function that returns a value. + * + * `Function` cannot be used instead because it doesn't accept class declarations. + * These would fail when invoked since they are invoked without the `new` keyword. + */ +export type Callable = ( + // 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 + ...args: any[] +) => unknown; + +/** + * Type that represents a single method/function name of the given type. + */ +export type MethodOf<TObjectType, TSignature extends Callable = Callable> = { + [Key in keyof TObjectType]: TObjectType[Key] extends TSignature + ? Key extends string + ? Key + : never + : never; +}[keyof TObjectType]; + +/** + * Type that represents all method/function names of the given type. + */ +export type MethodsOf< + TObjectType, + TSignature extends Callable = Callable, +> = ReadonlyArray<MethodOf<TObjectType, TSignature>>; |
