-
-
Notifications
You must be signed in to change notification settings - Fork 547
/
pascal-cased-properties-deep.d.ts
55 lines (47 loc) · 1.19 KB
/
pascal-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
55
import type {CamelCaseOptions} from './camel-case';
import type {PascalCase} from './pascal-case';
/**
Convert object properties to pascal case recursively.
This can be useful when, for example, converting some API types from a different style.
@see PascalCase
@see PascalCasedProperties
@example
```
import type {PascalCasedPropertiesDeep} from 'type-fest';
interface User {
userId: number;
userName: string;
}
interface UserWithFriends {
userInfo: User;
userFriends: User[];
}
const result: PascalCasedPropertiesDeep<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 PascalCasedPropertiesDeep<Value, Options extends CamelCaseOptions = {preserveConsecutiveUppercase: true}> = Value extends Function | Date | RegExp
? Value
: Value extends Array<infer U>
? Array<PascalCasedPropertiesDeep<U, Options>>
: Value extends Set<infer U>
? Set<PascalCasedPropertiesDeep<U, Options>> : {
[K in keyof Value as PascalCase<K, Options>]: PascalCasedPropertiesDeep<Value[K], Options>;
};