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

P.not(P.nullish) on optional recursive type results in "Type instantiation is excessively deep and possibly infinite" #143

Open
paladdins opened this issue Feb 6, 2023 · 5 comments

Comments

@paladdins
Copy link

paladdins commented Feb 6, 2023

Describe the bug

Using .with({key: P.not(P.nullish)}).exhaustive() where key is defined as optional (or nullable) recursive type.
Setting opposite template without P.not() -> .with({key: P.nullish}).exhaustive() does not cause an error.

Custom function notNullish: <T>(value: T | null | undefined): value is T used with P.when .with({key: P.when(notNullish)}).exhaustive() works fine as a workaround

Code Sandbox with a minimal reproduction case (it takes approx a minute or less until TS gives up and throws error)
https://codesandbox.io/s/typescript-playground-export-forked-66dkq6?file=/index.ts

Versions

  • TypeScript version: 4.9.5
  • ts-pattern version: 4.1.3
  • environment: any
@paladdins
Copy link
Author

@gvergnaud just to ping)

@rodrigofariow
Copy link

rodrigofariow commented Mar 11, 2023

Hey 👋
I have the exact same issue when using ts-pattern 4.2.1.
I assume it really has to do with the combination of P.not with P.nullish.

The last version that works for me is ts-pattern 4.0.5

@jkomyno
Copy link

jkomyno commented Oct 27, 2023

Note: this issue is solved for me on ts-pattern@5.0.5

@tpetry
Copy link

tpetry commented Dec 13, 2023

Still happening for me with 5.0.6

@gvergnaud
Copy link
Owner

Here is a workaround:

const notNullable = P.when((x: unknown): x is {} => x != null)

It will be part of the next minor release as P.nonNullable.

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

No branches or pull requests

5 participants