type-fest
Version:
A collection of essential TypeScript types
69 lines (57 loc) • 1.56 kB
TypeScript
import type {CamelCaseOptions} from './camel-case.d.ts';
import type {CasedPropertiesDeep} from './internal/cased-properties-deep.d.ts';
import type {PascalCase} from './pascal-case.d.ts'; // For `@link`
import type {PascalCasedProperties} from './pascal-cased-properties.d.ts'; // For `@link`
/**
Convert object properties to pascal case recursively.
This can be useful when, for example, converting some API types from a different style.
```
import type {PascalCasedPropertiesDeep} from 'type-fest';
type User = {
userId: number;
userName: string;
};
type UserWithFriends = {
userInfo: User;
userFriends: User[];
};
const result: PascalCasedPropertiesDeep<UserWithFriends> = {
UserInfo: {
UserId: 1,
UserName: 'Tom',
},
UserFriends: [
{
UserId: 2,
UserName: 'Jerry',
},
{
UserId: 3,
UserName: 'Spike',
},
],
};
const preserveConsecutiveUppercase: PascalCasedPropertiesDeep<{fooBAR: {fooBARBiz: [{fooBARBaz: string}]}}, {preserveConsecutiveUppercase: true}> = {
FooBAR: {
FooBARBiz: [{
FooBARBaz: 'string',
}],
},
};
const noSplitOnPunctuation: PascalCasedPropertiesDeep<{'user@info': {'user::id': number; 'user::name': string}}, {splitOnPunctuation: false}> = {
'User@info': {
'User::id': 1,
'User::name': 'Tom',
},
};
```
*/
export type PascalCasedPropertiesDeep<Value, Options extends CamelCaseOptions = {}> =
CasedPropertiesDeep<Value, 'pascal', Options>;
export {};