Skip to content

Commit

Permalink
Add tests for identicality checks of any/never type parameters to…
Browse files Browse the repository at this point in the history
… `expectType`/`expectNotType` (#113)

Closes #78
Closes #82
  • Loading branch information
BendingBender committed Jun 3, 2021
1 parent 7fbb7a0 commit 009a185
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
5 changes: 5 additions & 0 deletions source/test/fixtures/identicality/identical/index.test-d.ts
Expand Up @@ -6,3 +6,8 @@ expectType<number>(concat(1, 2));

expectType<any>(concat(1, 2));
expectType<string | number>(concat('unicorn', 'rainbow'));

expectType<false>(concat(1, 2) as any);

expectType<string>('' as never);
expectType<any>('' as never);
Expand Up @@ -5,3 +5,6 @@ expectNotType<number>(concat('foo', 'bar'));
expectNotType<string | number>(concat('foo', 'bar'));

expectNotType<string>(concat('unicorn', 'rainbow'));

expectNotType<false>(concat('foo', 'bar') as any);
expectNotType<any>(concat('foo', 'bar') as any);
8 changes: 6 additions & 2 deletions source/test/identicality.ts
Expand Up @@ -8,14 +8,18 @@ test('identical', async t => {

verify(t, diagnostics, [
[7, 0, 'error', 'Parameter type `any` is not identical to argument type `number`.'],
[8, 0, 'error', 'Parameter type `string | number` is declared too wide for argument type `string`.']
[8, 0, 'error', 'Parameter type `string | number` is declared too wide for argument type `string`.'],
[10, 0, 'error', 'Parameter type `false` is not identical to argument type `any`.'],
[12, 0, 'error', 'Parameter type `string` is declared too wide for argument type `never`.'],
[13, 0, 'error', 'Parameter type `any` is declared too wide for argument type `never`.'],
]);
});

test('not identical', async t => {
const diagnostics = await tsd({cwd: path.join(__dirname, 'fixtures/identicality/not-identical')});

verify(t, diagnostics, [
[7, 0, 'error', 'Parameter type `string` is identical to argument type `string`.']
[7, 0, 'error', 'Parameter type `string` is identical to argument type `string`.'],
[10, 0, 'error', 'Parameter type `any` is identical to argument type `any`.'],
]);
});

0 comments on commit 009a185

Please sign in to comment.