forked from sindresorhus/camelcase-keys
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.test-d.ts
56 lines (40 loc) · 1.49 KB
/
index.test-d.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
import {expectType} from 'tsd';
import camelcaseKeys = require('.');
const fooBarObject = {'foo-bar': true};
const camelFooBarObject = camelcaseKeys(fooBarObject);
expectType<typeof fooBarObject>(camelFooBarObject);
const fooBarArray = [{'foo-bar': true}];
const camelFooBarArray = camelcaseKeys(fooBarArray);
expectType<typeof fooBarArray>(camelFooBarArray);
expectType<Array<{[key in 'foo-bar']: true}>>(camelcaseKeys([{'foo-bar': true}]));
expectType<string[]>(camelcaseKeys(['name 1', 'name 2']));
expectType<string[]>(camelcaseKeys(['name 1', 'name 2'], {deep: true}));
expectType<{[key in 'foo-bar']: true}>(camelcaseKeys({'foo-bar': true}));
expectType<{[key in 'foo-bar']: true}>(
camelcaseKeys({'foo-bar': true}, {deep: true}),
);
expectType<{[key in 'foo-bar']: true}>(
camelcaseKeys({'foo-bar': true}, {deep: true, pascalCase: true}),
);
expectType<{[key in 'foo-bar']: true}>(
camelcaseKeys({'foo-bar': true}, {exclude: ['foo', /bar/]}),
);
expectType<{[key in 'foo-bar']: true}>(
camelcaseKeys({'foo-bar': true}, {stopPaths: ['foo']}),
);
interface SomeObject {
someProperty: string;
}
const someObj: SomeObject = {
someProperty: 'hello'
};
expectType<SomeObject>(camelcaseKeys(someObj));
expectType<SomeObject[]>(camelcaseKeys([someObj]));
type SomeTypeAlias = {
someProperty: string;
}
const objectWithTypeAlias = {
someProperty: 'this should also work'
};
expectType<SomeTypeAlias>(camelcaseKeys(objectWithTypeAlias));
expectType<SomeTypeAlias[]>(camelcaseKeys([objectWithTypeAlias]));