|
1 |
| -import {expectType, expectAssignable} from 'tsd'; |
| 1 | +import {expectTypeOf} from 'expect-type'; |
2 | 2 | import {getProperty, setProperty, hasProperty, deleteProperty} from './index.js';
|
3 | 3 |
|
4 |
| -expectType<string>(getProperty({foo: {bar: 'unicorn'}}, 'foo.bar')); |
5 |
| -expectType<undefined>(getProperty({foo: {bar: 'a'}}, 'foo.notDefined.deep')); |
6 |
| -expectAssignable<string>( |
| 4 | +expectTypeOf(getProperty({foo: {bar: 'unicorn'}}, 'foo.bar')).toBeString(); |
| 5 | +expectTypeOf(getProperty({foo: {bar: 'a'}}, 'foo.notDefined.deep')).toBeUndefined(); |
| 6 | +expectTypeOf( |
7 | 7 | getProperty({foo: {bar: 'a'}}, 'foo.notDefined.deep', 'default value'),
|
8 |
| -); |
9 |
| -expectType<string>( |
| 8 | +).toBeString(); |
| 9 | +expectTypeOf( |
10 | 10 | getProperty({foo: {'dot.dot': 'unicorn'}}, 'foo.dot\\.dot'),
|
11 |
| -); |
| 11 | + // @ts-expect-error type-fest's `Get` not smart enough to deal with escaped dots |
| 12 | +).toEqualTypeOf<string>(); |
12 | 13 |
|
13 | 14 | const object = {foo: {bar: 'a'}};
|
14 |
| -expectType<typeof object>(setProperty(object, 'foo.bar', 'b')); |
| 15 | +expectTypeOf(setProperty(object, 'foo.bar', 'b')).toEqualTypeOf(object); |
15 | 16 |
|
16 |
| -expectType<boolean>(hasProperty({foo: {bar: 'unicorn'}}, 'foo.bar')); |
| 17 | +expectTypeOf(hasProperty({foo: {bar: 'unicorn'}}, 'foo.bar')).toEqualTypeOf<boolean>(); |
17 | 18 |
|
18 |
| -expectType<boolean>(deleteProperty({foo: {bar: 'a'}}, 'foo.bar')); |
| 19 | +expectTypeOf(deleteProperty({foo: {bar: 'a'}}, 'foo.bar')).toEqualTypeOf<boolean>(); |
0 commit comments