-
-
Notifications
You must be signed in to change notification settings - Fork 594
/
Copy pathcamel-cased-properties.d.ts
43 lines (35 loc) · 1.03 KB
/
camel-cased-properties.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
import type {CamelCase, CamelCaseOptions, DefaultCamelCaseOptions} from './camel-case';
import type {ApplyDefaultOptions} from './internal';
/**
Convert object properties to camel case but not recursively.
This can be useful when, for example, converting some API types from a different style.
@see CamelCasedPropertiesDeep
@see CamelCase
@example
```
import type {CamelCasedProperties} from 'type-fest';
interface User {
UserId: number;
UserName: string;
}
const result: CamelCasedProperties<User> = {
userId: 1,
userName: 'Tom',
};
const preserveConsecutiveUppercase: CamelCasedProperties<{fooBAR: string}, {preserveConsecutiveUppercase: false}> = {
fooBar: 'string',
};
```
@category Change case
@category Template literal
@category Object
*/
export type CamelCasedProperties<Value, Options extends CamelCaseOptions = {}> = Value extends Function
? Value
: Value extends Array<infer U>
? Value
: {
[K in keyof Value as
CamelCase<K, ApplyDefaultOptions<CamelCaseOptions, DefaultCamelCaseOptions, Options>>
]: Value[K];
};