Skip to content

Commit

Permalink
support never for type testing (#37)
Browse files Browse the repository at this point in the history
  • Loading branch information
huan committed Mar 25, 2022
1 parent 0917837 commit 4a9462a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
12 changes: 12 additions & 0 deletions src/assert-equal.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,15 @@ test('AssertEqual smoke testing', async (t) => {

t.ok(typeTest, 'should pass the typing test')
})

/**
* Issue #37
* @link https://github.com/huan/tstest/issues/37
*/
test('AssertEqual with `never`', async (t) => {
type T = never
type EXPECTED_TYPE = never
const typeTest: AssertEqual<T, EXPECTED_TYPE> = true

t.ok(typeTest, 'should pass the typing test')
})
4 changes: 2 additions & 2 deletions src/assert-equal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
* https://2ality.com/2019/07/testing-static-types.html
*/
type AssertEqual<T, Expected> =
T extends Expected
? (Expected extends T ? true : never)
[T] extends [Expected]
? ([Expected] extends [T] ? true : never)
: never

export type {
Expand Down

0 comments on commit 4a9462a

Please sign in to comment.