From 009a18521f8822e669ecee0f12003d9ccf4384d9 Mon Sep 17 00:00:00 2001 From: Dimitri B Date: Thu, 3 Jun 2021 12:09:53 +0200 Subject: [PATCH] Add tests for identicality checks of `any`/`never` type parameters to `expectType`/`expectNotType` (#113) Closes #78 Closes #82 --- .../test/fixtures/identicality/identical/index.test-d.ts | 5 +++++ .../fixtures/identicality/not-identical/index.test-d.ts | 3 +++ source/test/identicality.ts | 8 ++++++-- 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/source/test/fixtures/identicality/identical/index.test-d.ts b/source/test/fixtures/identicality/identical/index.test-d.ts index e3950cc3..1af8c764 100644 --- a/source/test/fixtures/identicality/identical/index.test-d.ts +++ b/source/test/fixtures/identicality/identical/index.test-d.ts @@ -6,3 +6,8 @@ expectType(concat(1, 2)); expectType(concat(1, 2)); expectType(concat('unicorn', 'rainbow')); + +expectType(concat(1, 2) as any); + +expectType('' as never); +expectType('' as never); diff --git a/source/test/fixtures/identicality/not-identical/index.test-d.ts b/source/test/fixtures/identicality/not-identical/index.test-d.ts index 9dd769df..09c08c3c 100644 --- a/source/test/fixtures/identicality/not-identical/index.test-d.ts +++ b/source/test/fixtures/identicality/not-identical/index.test-d.ts @@ -5,3 +5,6 @@ expectNotType(concat('foo', 'bar')); expectNotType(concat('foo', 'bar')); expectNotType(concat('unicorn', 'rainbow')); + +expectNotType(concat('foo', 'bar') as any); +expectNotType(concat('foo', 'bar') as any); diff --git a/source/test/identicality.ts b/source/test/identicality.ts index c69fa1f4..96a84e1b 100644 --- a/source/test/identicality.ts +++ b/source/test/identicality.ts @@ -8,7 +8,10 @@ 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`.'], ]); }); @@ -16,6 +19,7 @@ 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`.'], ]); });