-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update the `deepEqual`, `like`, `false`, `true` and `is` assertions so they can be used as type guards. Fixes #2456. Change the `deepEqual`, `like` and `is` assertions so the actual and expected parameters can be typed separately. Fixes #2580.
- Loading branch information
1 parent
72a4e2f
commit 5eea608
Showing
2 changed files
with
47 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import {expectType} from 'tsd'; | ||
import test from '..'; | ||
|
||
type Expected = {foo: 'bar'}; | ||
const expected: Expected = {foo: 'bar'}; | ||
|
||
test('deepEqual', t => { | ||
const actual: unknown = {}; | ||
if (t.deepEqual(actual, expected)) { | ||
expectType<Expected>(actual); | ||
} | ||
}); | ||
|
||
test('like', t => { | ||
const actual: unknown = {}; | ||
if (t.like(actual, expected)) { | ||
expectType<Expected>(actual); | ||
} | ||
}); | ||
|
||
test('is', t => { | ||
const actual: unknown = 2; | ||
if (t.is(actual, 3 as const)) { | ||
expectType<3>(actual); | ||
} | ||
}); | ||
|
||
test('false', t => { | ||
const actual: unknown = true; | ||
if (t.false(actual)) { | ||
expectType<false>(actual); | ||
} | ||
}); | ||
|
||
test('true', t => { | ||
const actual: unknown = false; | ||
if (t.true(actual)) { | ||
expectType<true>(actual); | ||
} | ||
}); |