-
-
Notifications
You must be signed in to change notification settings - Fork 66
/
index.test-d.ts
19 lines (15 loc) · 857 Bytes
/
index.test-d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
import {expectTypeOf} from 'expect-type';
import {getProperty, setProperty, hasProperty, deleteProperty} 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'),
// @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>();