forked from sindresorhus/type-fest
-
Notifications
You must be signed in to change notification settings - Fork 0
/
camel-cased-properties-deep.d.ts
54 lines (46 loc) · 1 KB
/
camel-cased-properties-deep.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import type {CamelCase} from './camel-case';
/**
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<UserWithFriends> = {
userInfo: {
userId: 1,
userName: 'Tom',
},
userFriends: [
{
userId: 2,
userName: 'Jerry',
},
{
userId: 3,
userName: 'Spike',
},
],
};
```
@category Change case
@category Template literal
@category Object
*/
export type CamelCasedPropertiesDeep<Value> = Value extends Function
? Value
: Value extends Array<infer U>
? Array<CamelCasedPropertiesDeep<U>>
: Value extends Set<infer U>
? Set<CamelCasedPropertiesDeep<U>> : {
[K in keyof Value as CamelCase<K>]: CamelCasedPropertiesDeep<Value[K]>;
};