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

Perf: support exhaustive match on larger unions #214

Merged
merged 3 commits into from
Jan 13, 2024

Conversation

gvergnaud
Copy link
Owner

in v5.0.6, .exhaustive() might throw a "recursion is possibly infinite" error on input types with a distributed cardinality of more than |500|. For example this type:

type State = 'idle' | 'loading' | 'success' | 'error' | 'partial_result'

type Input = {
  a: State,
  b: State,
  c: State,
  d: State,
};

has a cardinality of 5^4 == 625 entries. If your pattern matches all keys of this object and you use .exhaustive(), TS-Pattern will distribute this type and turn it into a union of 625 objects in order to compute unhandled cases. This currently reaches typescript recursion limit. This PR makes slight changes to avoid reaching limit as early.

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.

1 participant