Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Loosen type constraints for deepEqual assertion
Allow actual to extend expected, or for the types to not extend each other at all.
- Loading branch information
1 parent
b5f934d
commit 9f797b0
Showing
2 changed files
with
42 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import {expectType} from 'tsd'; | ||
|
||
import test from '..'; | ||
|
||
test('actual extends expected', t => { | ||
type Expected = {foo: [1, 2, 3]}; | ||
const expected: Expected = {foo: [1, 2, 3]}; | ||
const actual = {foo: [1, 2, 3]}; | ||
if (t.deepEqual(actual, expected)) { | ||
expectType<Expected>(actual); | ||
} | ||
}); | ||
|
||
test('expected extends actual', t => { | ||
type Expected = {foo: Array<number | string>}; | ||
type Actual = {foo: number[]}; | ||
const expected: Expected = {foo: [1, 2, 3]}; | ||
const actual: Actual = {foo: [1, 2, 3]}; | ||
if (t.deepEqual(actual, expected)) { | ||
expectType<Actual>(expected); | ||
} | ||
}); | ||
|
||
test('neither extends the each other', t => { | ||
type Expected = {readonly foo: readonly [1, 2, 3]}; | ||
type Actual = {foo: number[]}; | ||
const expected: Expected = {foo: [1, 2, 3]}; | ||
const actual: Actual = {foo: [1, 2, 3]}; | ||
t.deepEqual(actual, expected); | ||
}); |
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