import type {CamelCase, CamelCaseOptions, _DefaultCamelCaseOptions} from './camel-case.d.ts'; import type {ApplyDefaultOptions, NonRecursiveType} from './internal/index.d.ts'; import type {UnknownArray} from './unknown-array.d.ts'; /** Convert object properties to camel case recursively. This can be useful when, for example, converting some API types from a different style. @see CamelCasedProperties @see CamelCase @example ``` import type {CamelCasedPropertiesDeep} from 'type-fest'; interface User { UserId: number; UserName: string; } interface UserWithFriends { UserInfo: User; UserFriends: User[]; } const result: CamelCasedPropertiesDeep = { userInfo: { userId: 1, userName: 'Tom', }, userFriends: [ { userId: 2, userName: 'Jerry', }, { userId: 3, userName: 'Spike', }, ], }; const preserveConsecutiveUppercase: CamelCasedPropertiesDeep<{fooBAR: {fooBARBiz: [{fooBARBaz: string}]}}, {preserveConsecutiveUppercase: true}> = { fooBAR: { fooBARBiz: [{ fooBARBaz: 'string', }], }, }; ``` @category Change case @category Template literal @category Object */ export type CamelCasedPropertiesDeep< Value, Options extends CamelCaseOptions = {}, > = _CamelCasedPropertiesDeep>; type _CamelCasedPropertiesDeep< Value, Options extends Required, > = Value extends NonRecursiveType ? Value : Value extends UnknownArray ? CamelCasedPropertiesArrayDeep : Value extends Set ? Set<_CamelCasedPropertiesDeep> : Value extends object ? { [K in keyof Value as CamelCase]: _CamelCasedPropertiesDeep; } : Value; // This is a copy of DelimiterCasedPropertiesArrayDeep (see: delimiter-cased-properties-deep.d.ts). // These types should be kept in sync. type CamelCasedPropertiesArrayDeep< Value extends UnknownArray, Options extends Required, > = Value extends [] ? [] // Trailing spread array : Value extends [infer U, ...infer V] ? [_CamelCasedPropertiesDeep, ..._CamelCasedPropertiesDeep] : Value extends readonly [infer U, ...infer V] ? readonly [_CamelCasedPropertiesDeep, ..._CamelCasedPropertiesDeep] : // Leading spread array Value extends readonly [...infer U, infer V] ? [..._CamelCasedPropertiesDeep, _CamelCasedPropertiesDeep] : // Array Value extends Array ? Array<_CamelCasedPropertiesDeep> : Value extends ReadonlyArray ? ReadonlyArray<_CamelCasedPropertiesDeep> : never; export {};