forked from sindresorhus/type-fest
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcamel-cased-properties.ts
More file actions
44 lines (33 loc) · 1.65 KB
/
camel-cased-properties.ts
File metadata and controls
44 lines (33 loc) · 1.65 KB
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
44
import {expectType} from 'tsd';
import type {CamelCasedProperties} from '../index.d.ts';
declare const foo: CamelCasedProperties<{A: number; B: {C: string}}>;
expectType<{a: number; b: {C: string}}>(foo);
declare const bar: CamelCasedProperties<Array<{helloWorld: string}>>;
expectType<Array<{helloWorld: string}>>(bar);
declare const fooBar: CamelCasedProperties<() => {a: string}>;
expectType<() => {a: string}>(fooBar);
declare const baz: CamelCasedProperties<{fooBAR: number; BARFoo: string}, {preserveConsecutiveUppercase: true}>;
expectType<{fooBAR: number; bARFoo: string}>(baz);
declare const biz: CamelCasedProperties<{fooBAR: number; BARFoo: string}>;
expectType<{fooBar: number; barFoo: string}>(biz);
declare const fooBarPunctuated: CamelCasedProperties<{'hello@world1': {'foo::bar': string}}>;
expectType<{'hello@world1': {'foo::bar': string}}>(fooBarPunctuated);
declare const fooBarPunctuatedSplit: CamelCasedProperties<{'hello@world1': {'foo::bar': string}}, {splitOnPunctuation: true}>;
expectType<{'helloWorld1': {'foo::bar': string}}>(fooBarPunctuatedSplit);
declare const fooBarPunctuatedSplitNumberSplit: CamelCasedProperties<{'hello@world1': {'foo::bar': string}}, {splitOnPunctuation: true; splitOnNumbers: true}>;
expectType<{'helloWorld1': {'foo::bar': string}}>(fooBarPunctuatedSplitNumberSplit);
// Verify example
type User = {
UserId: number;
UserName: string;
};
type UserPunctuated = {
'user::id': number;
'user::name': string;
};
const result: CamelCasedProperties<User> = {
userId: 1,
userName: 'Tom',
};
expectType<CamelCasedProperties<User>>(result);
expectType<CamelCasedProperties<UserPunctuated, {splitOnPunctuation: true}>>(result);