UNPKG

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