//#region src/types/utils.d.ts /** * Useful to flatten the type output to improve type hints shown in editors. And also to transform an interface into a type to aide with assignability. * https://github.com/sindresorhus/type-fest/blob/main/source/simplify.d.ts */ type Simplify = { [K in keyof T]: T[K] } & {}; type SnakeToCamel = T extends `${infer A}_${infer B}` ? `${Uncapitalize}${Capitalize>}` : T extends object ? { [K in keyof T as SnakeToCamel]: T[K] } : T; type DeepSnakeToCamel = T extends `${infer A}_${infer B}` ? `${Uncapitalize}${Capitalize>}` : T extends object ? { [K in keyof T as DeepSnakeToCamel]: DeepSnakeToCamel } : T; type DeepCamelToSnake = T extends `${infer C0}${infer R}` ? `${C0 extends Uppercase ? '_' : ''}${Lowercase}${DeepCamelToSnake}` : T extends object ? { [K in keyof T as DeepCamelToSnake>]: DeepCamelToSnake } : T; type CamelToSnake = T extends `${infer C0}${infer R}` ? `${C0 extends Uppercase ? '_' : ''}${Lowercase}${CamelToSnake}` : T extends object ? { [K in keyof T as CamelToSnake>]: T[K] } : T; /** * @internal */ type DeepPartial = { [P in keyof T]?: T[P] extends object ? DeepPartial : T[P] }; type DeepRequired = Required<{ [P in keyof T]: T[P] extends object | undefined ? DeepRequired> : T[P] }>; type Nullable = { [P in keyof T]: P extends K ? T[P] | null : T[P] }; /** * Internal type used by RecordToPath */ type PathImpl = Key extends string ? T[Key] extends Record ? `${Key}.${PathImpl> & string}` | `${Key}.${Exclude & string}` : never : never; /** * Internal type used by RecordToPath */ type PathImpl2 = PathImpl | keyof T; /** * Used to construct a type union containing all the keys (even if nested) of an object defined as const * const obj = { a: { b: '' }, c: '' } as const; * type Paths = RecordToPath * Paths contains: 'a' | 'a.b' | 'c' */ type RecordToPath = PathImpl2 extends string | keyof T ? PathImpl2 : keyof T; /** * Used to read the value of a string path inside an object defined as const * const obj = { a: { b: 'hello' }} as const; * type Value = PathValue * Value is now a union set containing a single type: 'hello' */ type PathValue> = P extends `${infer Key}.${infer Rest}` ? Key extends keyof T ? Rest extends RecordToPath ? PathValue : never : never : P extends keyof T ? T[P] : never; type IsSerializable = T extends Function ? false : true; /** * Excludes any non-serializable prop from an object * * @hidden */ type Serializable = { [K in keyof T as IsSerializable extends true ? K : never]: T[K] }; /** * Enables autocompletion for a union type, while keeping the ability to use any string * or type of `T` * * @internal */ type Autocomplete = U | (T & Record); /** * Omit without union flattening */ type Without = { [P in keyof T as Exclude]: T[P] }; /** * Overrides the type of existing properties * const obj = { a: string, b: number } as const; * type Value = Override * Value contains: { a:string, b: string } */ type Override = Omit & U; /** * Utility type that removes function properties from a type. */ type RemoveFunctions = { [K in keyof T as T[K] extends ((...args: any[]) => any) ? never : K]: T[K] }; /** * Utility type that makes all properties `null`. */ type ForceNull = { [K in keyof T]: null }; //#endregion export { Autocomplete, CamelToSnake, DeepCamelToSnake, DeepPartial, DeepRequired, DeepSnakeToCamel, ForceNull, Nullable, Override, PathValue, RecordToPath, RemoveFunctions, Serializable, Simplify, SnakeToCamel, Without }; //# sourceMappingURL=utils.d.ts.map