Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve typings for t.is and t.deepEqual #2575

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ export interface AssertAssertion {

export interface DeepEqualAssertion {
/** Assert that `actual` is [deeply equal](https://github.com/concordancejs/concordance#comparison-details) to `expected`. */
<ValueType = any>(actual: ValueType, expected: ValueType, message?: string): void;
<ValueType = any, ValueType_ extends ValueType = ValueType>(actual: ValueType, expected: ValueType_, message?: string): void; // See #2575

/** Skip this assertion. */
skip(actual: any, expected: any, message?: string): void;
Expand Down Expand Up @@ -165,7 +165,7 @@ export interface IsAssertion {
* Assert that `actual` is [the same
* value](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is) as `expected`.
*/
<ValueType = any>(actual: ValueType, expected: ValueType, message?: string): void;
<ValueType = any, ValueType_ extends ValueType = ValueType>(actual: ValueType, expected: ValueType_, message?: string): void; // See #2575

/** Skip this assertion. */
skip(actual: any, expected: any, message?: string): void;
Expand All @@ -176,15 +176,15 @@ export interface NotAssertion {
* Assert that `actual` is not [the same
* value](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is) as `expected`.
*/
<ValueType = any>(actual: ValueType, expected: ValueType, message?: string): void;
<ValueType = any, ValueType_ extends ValueType = ValueType>(actual: ValueType, expected: ValueType_, message?: string): void; // See #2575

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

export interface NotDeepEqualAssertion {
/** Assert that `actual` is not [deeply equal](https://github.com/concordancejs/concordance#comparison-details) to `expected`. */
<ValueType = any>(actual: ValueType, expected: ValueType, message?: string): void;
<ValueType = any, ValueType_ extends ValueType = ValueType>(actual: ValueType, expected: ValueType_, message?: string): void; // See #2575

/** Skip this assertion. */
skip(actual: any, expected: any, message?: string): void;
Expand Down
16 changes: 16 additions & 0 deletions test-d/regression-2575.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import {expectError} from 'tsd';
import {IsAssertion, NotAssertion, DeepEqualAssertion, NotDeepEqualAssertion} from '..';

declare const is: IsAssertion;
declare const not: NotAssertion;
declare const deepEqual: DeepEqualAssertion;
declare const notDeepEqual: NotDeepEqualAssertion;

declare const literalStringUnionValue: 'hello' | 'world';
declare const objectWithLiteralStringUnionValue: {foo: 'hello' | 'world'};

// See #2575 and https://github.com/microsoft/TypeScript/issues/40377
expectError(is(literalStringUnionValue, 'another-string'));
expectError(not(literalStringUnionValue, 'another-string'));
expectError(deepEqual(objectWithLiteralStringUnionValue, {foo: 'another-string'}));
expectError(notDeepEqual(objectWithLiteralStringUnionValue, {foo: 'another-string'}));