UNPKG

798 BTypeScriptView Raw
1import type {CamelCase, CamelCaseOptions} from './camel-case';
2
3/**
4Convert object properties to camel case but not recursively.
5
6This can be useful when, for example, converting some API types from a different style.
7
8@see CamelCasedPropertiesDeep
9@see CamelCase
10
11@example
12```
13import type {CamelCasedProperties} from 'type-fest';
14
15interface User {
16 UserId: number;
17 UserName: string;
18}
19
20const result: CamelCasedProperties<User> = {
21 userId: 1,
22 userName: 'Tom',
23};
24```
25
26@category Change case
27@category Template literal
28@category Object
29*/
30export type CamelCasedProperties<Value, Options extends CamelCaseOptions = {preserveConsecutiveUppercase: true}> = Value extends Function
31 ? Value
32 : Value extends Array<infer U>
33 ? Value
34 : {
35 [K in keyof Value as CamelCase<K, Options>]: Value[K];
36 };