From d2b0c2b7bd2acc181b6f2b4e15420333be7033fb Mon Sep 17 00:00:00 2001 From: Rebecca Stevens Date: Mon, 14 Feb 2022 22:53:58 +1300 Subject: [PATCH] fix(DeepEqualAssertion): allow Actual and Expected types not to extend each other fix #2964 --- test-d/deep-equal.ts | 32 ++++++++++++++++++++++++++++++++ types/assertions.d.ts | 12 ++++++++++++ 2 files changed, 44 insertions(+) create mode 100644 test-d/deep-equal.ts diff --git a/test-d/deep-equal.ts b/test-d/deep-equal.ts new file mode 100644 index 0000000000..a7c5984419 --- /dev/null +++ b/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(actual); + } +}); + +test('expected extends actual', t => { + type Expected = {foo: Array}; + type Actual = {foo: number[]}; + const expected: Expected = {foo: [1, 2, 3]}; + const actual: Actual = {foo: [1, 2, 3]}; + if (t.deepEqual(actual, expected)) { + expectType(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(); + } +}); diff --git a/types/assertions.d.ts b/types/assertions.d.ts index 657ed3d486..ce5a97a140 100644 --- a/types/assertions.d.ts +++ b/types/assertions.d.ts @@ -138,6 +138,18 @@ export interface DeepEqualAssertion { */ (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: 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: Actual, expected: Expected, message?: string): boolean; + /** Skip this assertion. */ skip(actual: any, expected: any, message?: string): void; }