forked from sindresorhus/type-fest
-
Notifications
You must be signed in to change notification settings - Fork 0
/
camel-cased-properties-deep.ts
60 lines (49 loc) · 1.51 KB
/
camel-cased-properties-deep.ts
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import {expectType} from 'tsd';
import type {CamelCasedPropertiesDeep} from '../index';
declare const foo: CamelCasedPropertiesDeep<{A: {B: number; C: Array<{D: string}>}}>;
expectType<{a: {b: number; c: Array<{d: string}>}}>(foo);
declare const fooBar: CamelCasedPropertiesDeep<() => {a: string}>;
expectType<() => {a: string}>(fooBar);
declare const bar: CamelCasedPropertiesDeep<Set<{fooBar: string}>>;
expectType<Set<{fooBar: string}>>(bar);
type bazBizDeep = {fooBAR: number; baz: {fooBAR: number; BARFoo: string}};
declare const baz: CamelCasedPropertiesDeep<bazBizDeep>;
expectType<{fooBAR: number; baz: {fooBAR: number; bARFoo: string}}>(baz);
declare const biz: CamelCasedPropertiesDeep<bazBizDeep, {preserveConsecutiveUppercase: false}>;
expectType<{fooBar: number; baz: {fooBar: number; barFoo: string}}>(biz);
declare const tuple: CamelCasedPropertiesDeep<{tuple: [number, string, {D: string}]}>;
expectType<{tuple: [number, string, {d: string}]}>(tuple);
// Verify example
type User = {
UserId: number;
UserName: string;
Date: Date;
RegExp: RegExp;
};
type UserWithFriends = {
UserInfo: User;
UserFriends: User[];
};
const result: CamelCasedPropertiesDeep<UserWithFriends> = {
userInfo: {
userId: 1,
userName: 'Tom',
date: new Date(),
regExp: /.*/,
},
userFriends: [
{
userId: 2,
userName: 'Jerry',
date: new Date(),
regExp: /.*/,
},
{
userId: 3,
userName: 'Spike',
date: new Date(),
regExp: /.*/,
},
],
};
expectType<CamelCasedPropertiesDeep<UserWithFriends>>(result);