Skip to content

IsEqual: Fix generic inference#1306

Merged
sindresorhus merged 3 commits intosindresorhus:mainfrom
taiyakihitotsu:issue-1305
Dec 2, 2025
Merged

IsEqual: Fix generic inference#1306
sindresorhus merged 3 commits intosindresorhus:mainfrom
taiyakihitotsu:issue-1305

Conversation

@taiyakihitotsu
Copy link
Contributor

This PR fixes issue #1305.

This approach is similar to the fix previously implemented in 5af60a1.

Note:
I have intentionally ignored the @typescript-eslint/consistent-type-assertions rule in the test file (test-d/is-equal.ts) to accurately reflect and test the structure of the original reported issue code.

  test-d/is-equal.ts:94:3
  ✖  94:3   Always prefer const x: T = { ... }. 
  @typescript-eslint/consistent-type-assertions

@taiyakihitotsu taiyakihitotsu changed the title IsEqual: Fix generic inference issue. IsEqual: Fix generic inference issue #1305. Dec 1, 2025
@taiyakihitotsu taiyakihitotsu changed the title IsEqual: Fix generic inference issue #1305. IsEqual: Fix generic inference issue (#1305). Dec 1, 2025
@som-sm som-sm changed the title IsEqual: Fix generic inference issue (#1305). IsEqual: Fix generic inference Dec 1, 2025
Comment on lines +89 to +95
// 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
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
Contributor Author

Choose a reason for hiding this comment

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

Thanks, addressed.

@taiyakihitotsu taiyakihitotsu requested a review from som-sm December 1, 2025 19:15
@sindresorhus sindresorhus merged commit f7b2667 into sindresorhus:main Dec 2, 2025
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants