Skip to content

Commit

Permalink
Switch to expect-type
Browse files Browse the repository at this point in the history
  • Loading branch information
mmkal committed Jan 29, 2022
1 parent bf3c2a6 commit a3b3bad
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 13 deletions.
20 changes: 10 additions & 10 deletions index.test-d.ts
@@ -1,18 +1,18 @@
import {expectType, expectAssignable} from 'tsd';
import {expectTypeOf} from 'expect-type';
import {getProperty, setProperty, hasProperty, deleteProperty} from './index.js';

expectType<string>(getProperty({foo: {bar: 'unicorn'}}, 'foo.bar'));
expectType<undefined>(getProperty({foo: {bar: 'a'}}, 'foo.notDefined.deep'));
expectAssignable<string>(
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'),
);
expectType<string>(
).toBeString();
expectTypeOf(
getProperty({foo: {'dot.dot': 'unicorn'}}, 'foo.dot\\.dot'),
);
).toEqualTypeOf<string>();

const object = {foo: {bar: 'a'}};
expectType<typeof object>(setProperty(object, 'foo.bar', 'b'));
expectTypeOf(setProperty(object, 'foo.bar', 'b')).toEqualTypeOf(object);

expectType<boolean>(hasProperty({foo: {bar: 'unicorn'}}, 'foo.bar'));
expectTypeOf(hasProperty({foo: {bar: 'unicorn'}}, 'foo.bar')).toEqualTypeOf<boolean>();

expectType<boolean>(deleteProperty({foo: {bar: 'a'}}, 'foo.bar'));
expectTypeOf(deleteProperty({foo: {bar: 'a'}}, 'foo.bar')).toEqualTypeOf<boolean>();
7 changes: 4 additions & 3 deletions package.json
Expand Up @@ -16,7 +16,7 @@
"node": "^12.20.0 || ^14.13.1 || >=16.0.0"
},
"scripts": {
"test": "xo && ava && tsd",
"test": "xo && ava && tsc",
"bench": "node benchmark.js"
},
"files": [
Expand All @@ -42,7 +42,8 @@
"devDependencies": {
"ava": "^4.0.1",
"benchmark": "^2.1.4",
"tsd": "^0.19.1",
"expect-type": "^0.13.0",
"typescript": "^4.5.5",
"xo": "^0.47.0"
}
}
}
8 changes: 8 additions & 0 deletions tsconfig.json
@@ -0,0 +1,8 @@
{
"compilerOptions": {
"lib": ["es2020"],
"strict": true,
"noEmit": true
},
"include": ["*.ts"]
}

0 comments on commit a3b3bad

Please sign in to comment.