Skip to content

Commit

Permalink
fix(DeepEqualAssertion): allow Actual and Expected types not to exten…
Browse files Browse the repository at this point in the history
…d each other

fix #2964
  • Loading branch information
RebeccaStevens committed Feb 22, 2022
1 parent 576f534 commit 3029047
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
32 changes: 32 additions & 0 deletions test-d/deep-equal.ts
@@ -0,0 +1,32 @@
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 exectend 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]};
if (t.deepEqual(actual, expected)) {
t.pass();
}
});
12 changes: 12 additions & 0 deletions types/assertions.d.ts
Expand Up @@ -138,6 +138,18 @@ export interface DeepEqualAssertion {
*/
<Actual, Expected extends Actual>(actual: Actual, expected: Expected, message?: string): actual is Expected;

/**
* Assert that `actual` is [deeply equal](https://github.com/concordancejs/concordance#comparison-details) to
* `expected`, returning a boolean indicating whether the assertion passed.
*/
<Actual extends Expected, Expected>(actual: Actual, expected: Expected, message?: string): expected is Actual;

/**
* Assert that `actual` is [deeply equal](https://github.com/concordancejs/concordance#comparison-details) to
* `expected`, returning a boolean indicating whether the assertion passed.
*/
<Actual, Expected>(actual: Actual, expected: Expected, message?: string): boolean;

/** Skip this assertion. */
skip(actual: any, expected: any, message?: string): void;
}
Expand Down

0 comments on commit 3029047

Please sign in to comment.