UNPKG

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