Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
12 changes: 4 additions & 8 deletions source/is-equal.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,10 @@ type Includes<Value extends readonly any[], Item> =
@category Utilities
*/
export type IsEqual<A, B> =
[A, B] extends [infer AA, infer BB]
? [AA] extends [never]
? [BB] extends [never]
? true
: false
: [BB] extends [never]
? false
: _IsEqual<AA, BB>
[A] extends [B]
? [B] extends [A]
? _IsEqual<A, B>
: false
: false;

// This version fails the `equalWrappedTupleIntersectionToBeNeverAndNeverExpanded` test in `test-d/is-equal.ts`.
Expand Down
8 changes: 8 additions & 0 deletions test-d/is-equal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,3 +85,11 @@ expectType<true>(equalTupleIntersectionToBeNeverAndNeverExpanded);

declare const equalTupleIntersectionAndTuple: IsEqual<[{a: 1}] & [{a: 1}], [{a: 1}]>; // eslint-disable-line @typescript-eslint/no-duplicate-type-constituents
expectType<true>(equalTupleIntersectionAndTuple);

// Test for Issue https://github.com/sindresorhus/type-fest/issues/1305
type FieldProps<T1> = {
onChange: <T2>(value: T2, shouldBeTrue: IsEqual<T1, T2>) => void;
};
const _TextField = <T>(value: T) => {
({} as FieldProps<T>).onChange(value, true); // eslint-disable-line @typescript-eslint/consistent-type-assertions
};
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use the following test instead:

Suggested change
// Test for Issue https://github.com/sindresorhus/type-fest/issues/1305
type FieldProps<T1> = {
onChange: <T2>(value: T2, shouldBeTrue: IsEqual<T1, T2>) => void;
};
const _TextField = <T>(value: T) => {
({} as FieldProps<T>).onChange(value, true); // eslint-disable-line @typescript-eslint/consistent-type-assertions
};
type Assignability<T, U, _V extends IsEqual<T, U>> = any;
type TestAssignability<T> = Assignability<T, T, true>;

This is easier to understand and aligns with other generic assignability tests that we have.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, addressed.