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

Exact: Fix usage with recursive types and unions #949

Merged
merged 1 commit into from
Sep 8, 2024

Conversation

abrenneke
Copy link
Contributor

@abrenneke abrenneke commented Aug 28, 2024

Fixes #948

This moves IsEqual to be the first check, before any distribution, restoring the behavior before #911.

Wrote a test for it, and all tests are still passing, including those written for #911!

@abrenneke
Copy link
Contributor Author

@zorji I'm assuming because the tests pass, that this doesn't revert any of the behavior you fixed in #911 but it's possible I suppose?

@abrenneke abrenneke force-pushed the abrenneke/exact-isequal branch 2 times, most recently from ecbfeed to 031bcf6 Compare August 28, 2024 18:06
test-d/exact.ts Outdated
// @see https://github.com/sindresorhus/type-fest/issues/948
{
type A = {
a: A;
Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry, I don't understand this type. Looks like this is an infinite recursive type.

Do you actually mean the following?

type A = {
  a: Expected;
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, yes I think that's what I meant

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed. I think it would also test the same case with a?: A. As long as there's some sort of recursion in either of the types. TS doesn't even really care about the infinite recursion unless you try to actually instantiate or resolve the type 🤷

@zorji
Copy link
Contributor

zorji commented Sep 7, 2024

@abrenneke Sorry for the late reply. I think the implementation is OK but I have a question for the test case.

@sindresorhus sindresorhus changed the title Move IsEqual to be first in Exact comparison to short-circuit before distribution Exact: Fix usage with recursive types and unions Sep 8, 2024
@sindresorhus sindresorhus merged commit 91f6d39 into sindresorhus:main Sep 8, 2024
8 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.

Exact no longer works with recursive types + unions
3 participants