-
-
Notifications
You must be signed in to change notification settings - Fork 98
/
Copy pathindex.test-d.ts
30 lines (24 loc) · 1.05 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
import {expectTypeOf} from 'expect-type';
import {
getProperty,
setProperty,
hasProperty,
deleteProperty,
escapePath,
deepKeys,
} from './index.js';
expectTypeOf(getProperty({foo: {bar: 'unicorn'}}, 'foo.bar')).toBeString();
expectTypeOf(getProperty({foo: {bar: 'a'}}, 'foo.notDefined.deep')).toBeUndefined();
expectTypeOf(
getProperty({foo: {bar: 'a'}}, 'foo.notDefined.deep', 'default value'),
).toBeString();
expectTypeOf(
getProperty({foo: {'dot.dot': 'unicorn'}}, 'foo.dot\\.dot'), // eslint-disable-line @typescript-eslint/naming-convention
// @ts-expect-error type-fest's `Get` not smart enough to deal with escaped dots
).toEqualTypeOf<string>();
const object = {foo: {bar: 'a'}};
expectTypeOf(setProperty(object, 'foo.bar', 'b')).toEqualTypeOf(object);
expectTypeOf(hasProperty({foo: {bar: 'unicorn'}}, 'foo.bar')).toEqualTypeOf<boolean>();
expectTypeOf(deleteProperty({foo: {bar: 'a'}}, 'foo.bar')).toEqualTypeOf<boolean>();
expectTypeOf(escapePath('foo.bar')).toEqualTypeOf<string>();
expectTypeOf(deepKeys({foo: {bar: 'a'}})).toEqualTypeOf<string[]>();