Skip to content

Commit

Permalink
Add test for generic parameter inference tsdjs#142
Browse files Browse the repository at this point in the history
  • Loading branch information
skarab42 committed Oct 22, 2022
1 parent 55f340f commit d6f728f
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
11 changes: 11 additions & 0 deletions source/test/fixtures/jest-like-api/identical-to/index.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,14 @@ assertType<string>().identicalTo<number>();
assertType<number>().identicalTo(fooString);
assertType(fooString).identicalTo<number>();
assertType(fooString).identicalTo(fooNumber);

// Should handle generic, see https://github.com/SamVerschueren/tsd/issues/142
declare const inferrable: <T = 'foo'>() => T;

// Should pass
assertType<'foo'>().identicalTo(inferrable());
assertType(inferrable()).identicalTo('foo');

// Should fail
assertType<string>().identicalTo(inferrable());
assertType(inferrable()).identicalTo(fooString);
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,14 @@ assertType<string>().not.identicalTo<string>();
assertType<string>().not.identicalTo(fooString);
assertType(fooString).not.identicalTo<string>();
assertType(fooString).not.identicalTo(fooString);

// Should handle generic, see https://github.com/SamVerschueren/tsd/issues/142
declare const inferrable: <T = 'foo'>() => T;

// Should pass
assertType<string>().not.identicalTo(inferrable());
assertType(inferrable()).not.identicalTo(fooString);

// Should fail
assertType<'foo'>().not.identicalTo(inferrable());
assertType(inferrable()).not.identicalTo('foo');
4 changes: 4 additions & 0 deletions source/test/jest-like-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ test('identical-to', async t => {
[14, 0, 'error', 'Parameter type `number` is not identical to argument type `string`.'],
[15, 0, 'error', 'Parameter type `string` is not identical to argument type `number`.'],
[16, 0, 'error', 'Parameter type `string` is not identical to argument type `number`.'],
[26, 0, 'error', 'Parameter type `string` is not identical to argument type `"foo"`.'],
[27, 0, 'error', 'Parameter type `"foo"` is not identical to argument type `string`.'],
]);
});

Expand All @@ -41,6 +43,8 @@ test('not-identical-to', async t => {
[14, 0, 'error', 'Parameter type `string` is identical to argument type `string`.'],
[15, 0, 'error', 'Parameter type `string` is identical to argument type `string`.'],
[16, 0, 'error', 'Parameter type `string` is identical to argument type `string`.'],
[26, 0, 'error', 'Parameter type `"foo"` is identical to argument type `"foo"`.'],
[27, 0, 'error', 'Parameter type `"foo"` is identical to argument type `"foo"`.'],
]);
});

Expand Down

0 comments on commit d6f728f

Please sign in to comment.