/** THIS IS AUTOGENERATED FILE FROM "utils/types.ts" */ /** * Extracts all values from an object or array type. * * @template T - The input type to extract values from * @returns The union of all possible values in T */ type ValueOf = T[keyof T]; /** * Extracts enum keys as a union type. * * @template T - The enum type to extract keys from * @returns A union of all string keys in the enum */ type ExtractEnumKeys = ValueOf<{ [key in keyof T]: key extends string ? key : never; }>; /** * Extracts enum values as a union type. * * @template T - The enum type to extract values from * @returns A union of all string and numeric values in the enum */ type ExtractEnumValues = `${T & string}` | (T & number); /** * Represents a type that can be either the specified type or `undefined` or `null`. * * @template T - The input type * @returns T or `undefined` or `null` */ type Maybe = Nullable | undefined; /** * Removes `null` and `undefined` from a type. */ type NotMaybe = Exclude; /** * Represents a type that can be either the specified type or `null`. * * @template T - The type to make possibly `null` * @returns `T` or `null` */ type Nullable = T | null; /** * Removes `null` from a type. */ type NotNullable = Exclude; /** * Represents any object with any keys and any values. * * @returns Record with any keys and any values */ type AnyObject = Record; /** * Represents dictionary with any keys and expecting values; * * @returns Record with any keys and values */ type Dict = Record; /** * Represents an empty object with no properties. * * @returns Record with no keys and no values */ type EmptyObject = Record; /** * T or T[]; */ type MaybeArray = T | T[]; /** * Represents all primitive types in TypeScript. * * @returns Union of all primitive types */ type Primitive = null | undefined | string | number | boolean | symbol | bigint; /** * Represents any primitive type (string, number, boolean, null, or undefined). * * @deprecated use `Primitive` type * * @returns Union of all primitive types */ type AnyPrimitive = Primitive; /** * Represents any function type. * * @returns Function with any parameters and return type */ type AnyFunction = (...args: any) => any; /** * Converts a union type to an intersection type. * * @template U - The union type to convert * @returns Intersection of all types in the union */ type UnionToIntersection = (U extends any ? (k: U) => void : never) extends (k: infer I) => void ? I : never; /** * Represents falsy values (undefined, null, empty string, false, or 0). * * @returns Union of all falsy values */ type FalsyValues = undefined | null | '' | false | 0; /** * Represents a type that can be either the specified type, undefined, or any other falsy value. * * @template T - The type to make possibly falsy * @returns T, undefined, or a falsy value */ type MaybeFalsy = T | FalsyValues; type Fn = (...args: TArgs) => T; /** * Represents a type that can be either the specified type or a function returning that type. * * @template T - The type to make possibly a function * @template TArgs - Arguments type for the function * @returns T or a function that returns T */ type MaybeFn = T | Fn; /** * Represents a class constructor type. * * @template T - The type the class constructs * @template Args - Constructor arguments type * @returns Constructor function for T with specified arguments */ type Class = new (...args: Args) => T; /** * Creates a deeply partial version of a type, making all properties optional recursively. * * @template T - The type to make deeply partial * @returns A type with all properties optional at any depth */ type DeepPartial = T extends BrowserNativeObject ? T : { [K in keyof T]?: ExtractObjects extends never ? T[K] : DeepPartial; }; /** * Makes specified keys of a type optional while keeping the rest required. * * @template T - The original type * @template K - The keys to make optional * @returns A type with specified keys optional and others required */ type PartialKeys = Omit & Partial>; /** * Makes specified keys of a type possibly Maybe while keeping the rest required. * * @template T - The original type * @template TMaybeKeys - The keys to make possibly Maybe * @returns A type with specified keys possibly Maybe and others required */ type MaybeKeys = { [K in keyof T]: K extends TMaybeKeys ? Maybe : T[K]; }; /** * Makes specified keys of a type required while keeping the rest optional. * * @template T - The original type * @template K - The keys to make required * @returns A type with specified keys required and others optional */ type RequiredKeys = Omit & Required>; /** * Extracts the inner type from a Promise type. * * @deprecated use `Awaited` from stdlib of TypeScript * * @template T - The type that may be a Promise * @returns The resolved type of the Promise or T itself if not a Promise */ type Unpromise = T extends Promise ? TValue : T; /** * Makes all values in an object type possibly undefined. * * @template T - The object type to make values possibly undefined * @returns A type with all values possibly undefined */ type MaybeValues = { [K in keyof T]: Maybe; }; /** * Gets the keys of an object whose values match a specific type. * * @template T - The object type * @template TValues - The value type to match * @returns Union of keys whose values match TValues */ type KeyOfByValue = ValueOf<{ [K in keyof T]: T[K] extends TValues ? K : never; }>; /** * Picks properties from an object whose values match a specific type. * * @template T - The object type * @template TValues - The value type to match * @returns A type with only the properties whose values match TValues */ type PickByValue = Pick>; /** * Omits properties from an object whose values match a specific type. * * @template T - The object type * @template TValues - The value type to match * @returns A type with the properties whose values match TValues omitted */ type OmitByValue = Omit>; /** * Determines if all properties in a type are optional. * * @template T - The type to check * @returns True if all properties are optional, false otherwise */ type IsPartial = keyof T extends never ? true : { [K in keyof T]-?: undefined extends T[K] ? never : K; } extends { [K in keyof T]: never; } ? true : T extends EmptyObject ? true : false; /** * @deprecated use `IsPartial` . Better naming * * @template T - The type to check * @returns True if all properties are optional, false otherwise */ type AllPropertiesOptional = IsPartial; /** * Conditionally makes a type partially optional based on a condition. * * @template TCondition - The condition to check * @template TObject - The object type to make partial if condition is true * @returns Partial if TCondition is true, otherwise TObject */ type PartialIf = TCondition extends true ? Partial : TObject; /** * Converts a record type into an array of key-value pairs. * * @template T - The record type to convert * @returns Array of [key, value] tuples */ type RecordEntries = T extends Record ? [Keys, Values][] : T extends Partial> ? [Keys, Values][] : never; /** * Renames a key in an object type, preserving the optional nature of the property. * * @template TObject - The object type * @template TOldKey - The old key name * @template TNewKey - The new key name * @returns A type with the key renamed */ type RenameKey = Omit & IsPartial> extends true ? { [K in TNewKey]?: TObject[TOldKey]; } : { [K in TNewKey]: TObject[TOldKey]; }; /** * Determines if an object type is empty (has no properties). * * @template T - The object type to check * @returns True if the object is empty, false otherwise */ type IsObjectEmpty = T extends EmptyObject ? true : keyof T extends never ? true : never; /** * Determines if an array type is empty. * * @template T - The array type to check * @returns True if the array is empty, false otherwise */ type IsEmptyArray = T extends [] ? true : false; /** * Extracts the parameter types from a function type. * * @template T - The function type to extract parameters from * @returns Union of all possible parameter types */ type Params any> = T extends { (...args: infer P1): any; (...args: infer P2): any; } ? P1 | P2 : T extends (...args: infer P) => any ? P : never; /** * Represents browser native object types. * * @returns Union of browser native object types */ type BrowserNativeObject = Date | FileList | File | Element | Node; /** * Removes undefined from a type. * * @template T - The type to remove undefined from * @returns T with undefined removed */ type NonUndefined = T extends undefined ? never : T; /** * Creates a literal union type that includes both a specific literal type and a primitive type. * * @template T - The literal type * @template U - The primitive type * @returns Union of T and U with a private property to prevent widening */ type LiteralUnion = T | (U & { _?: never; }); /** * Extracts object types from a type, excluding primitives. * * @template T - The type to extract objects from * @returns T if it's an object, otherwise never */ type ExtractObjects = T extends infer U ? U extends object ? U : never : never; /** * Replace value in object by key * * @example * ```ts * type Test = { foo: string; bar?: number }; * type FixedTest = OverrideKey * // { foo: string; bar?: string } * ``` * * @template T - The object type * @template K - The key to replace * @template V - The new value type * @returns A type with the specified key replaced with the new value type */ type OverrideKey = { [KK in keyof T]: KK extends K ? V : T[KK]; }; /** * Checks if two types are equal. * * @template X - First type to compare * @template Y - Second type to compare * @returns True if types are equal, false otherwise */ type IfEquals = (() => T extends X ? 1 : 2) extends () => T extends Y ? 1 : 2 ? true : false; /** * Gets the writable keys of a type (keys that are not readonly). * * @template T - The type to extract writable keys from * @returns Union of keys that are not readonly */ type WritableKeys = { [K in keyof T]: IfEquals<{ [Q in K]: T[K]; }, { -readonly [Q in K]: T[K]; }> extends true ? K : never; }[keyof T]; /** * Gets the readonly keys of a type. * * @template T - The type to extract readonly keys from * @returns Union of keys that are readonly */ type ReadonlyKeys = { [P in keyof T]-?: IfEquals<{ [Q in P]: T[P]; }, { -readonly [Q in P]: T[P]; }> extends true ? never : P; }[keyof T]; /** * Gets the non-readonly properties of a type. * * @template T - The type to extract non-readonly properties from * @returns A type with only the non-readonly properties */ type NonReadonly = Pick>; /** * Determines if a type is an array. * * @template T - The type to check * @returns True if the type is an array, false otherwise */ type IsArray = T extends object ? T extends Function ? false : T extends any[] ? true : false : false; /** * Determines if a type is a function. * * @template T - The type to check * @returns True if the type is a function, false otherwise */ type IsFunction = T extends object ? T extends Function ? true : false : false; /** * Determines if a type is an object (but not an array or function). * * @template T - The type to check * @returns True if the type is an object, false otherwise */ type IsObject = T extends object ? T extends Function ? false : T extends any[] ? false : true : false; /** * Creates a deep copy of an object type, preserving the structure. * * @template T - The type to copy * @returns A deep copy of the type */ type CopyObject = IsObject extends true ? { [K in keyof T]: IsObject extends true ? CopyObject : T[K]; } : T; /** * Represents a type that can be either the specified type or a Promise resolving to that type. * * @template T - The type to make possibly a promise * @returns T or Promise */ type MaybePromise = T | Promise; /** * Makes specified keys of a type required while keeping the rest optional. * * @template TTarget - The original type * @template TKey - The key(s) to make required * @returns A type with specified keys required and others optional */ type WithRequired = TTarget & { [_ in TKey]: {}; }; /** * Extracts the index keys from an array type. * * @template T - The array type to extract index keys from * @returns Union of index keys (string representations of numbers) */ type IndexKeys = Extract; /** * Removes undefined from a type. * * @template T - The type to remove undefined from * @returns T with undefined removed */ type Defined = Exclude; /** * Check existing key in object (T) */ type HasKey = string extends keyof T ? false : TKey extends keyof T ? true : false; /** * @deprecated use `HasKey` */ type HasSpecificKey = HasKey; /** * Checks type is any * * Returns true if T is any */ type IsAny = 0 extends 1 & T ? true : false; type IsUnknown = [unknown] extends [T] ? true : false; /** * Helpful to use with union type literals (`'str1' | 'str2' | AnyString`) */ type AnyString = string & {}; /** * Helpful to use with union type literals (`1 | 2 | AnyNumber`) */ type AnyNumber = number & {}; /** * Helpful to use with union type literals (`true | AnyBoolean`) */ type AnyBoolean = boolean & {}; /** * Upperfirst string type. It will capitalize the first letter of the string * and leave the rest of the string unchanged. */ type UpperFirst = S extends `${infer F}${infer R}` ? `${Uppercase}${R}` : S;