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

Match + exhaustive doesn't work with readonly array #271

Closed
rikutiira opened this issue Aug 8, 2024 · 0 comments
Closed

Match + exhaustive doesn't work with readonly array #271

rikutiira opened this issue Aug 8, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@rikutiira
Copy link

rikutiira commented Aug 8, 2024

Describe the bug
Hey, first of all thanks for the awesome library 🙏 I have a small issue where .match() with .exhaustive() is not working with a readonly array, I included screenshots of the issue.

match(value) // value: string | Date | readonly string[]
  .with(P.string, (value) => ...)
  .with(P.array(P.string), (value) => ...)
  .with(P.instanceOf(Date), (value) => ...)
  .exhaustive() // Complains about "Type 'NonExhaustiveError<readonly string[]>' has no call signatures."

Interestingly enough, the value is correct inside the P.array(P.string)) condition: value: string[] | readonly string[].

TypeScript playground with a minimal reproduction case
https://www.typescriptlang.org/play/?#code/JYWwDg9gTgLgBAbziAhjAxgCwDRwApwC+cAZlBCHAOQwDOAtGGjAKZQB2VAUFzAJ5gWcAGooANgFchAXji0YUYOwDmcAD5woLFABMI7MXzkKlygNoBddXAAiaFgG4eOlujEotcdPvlwAbuJSAFwigY48qBiYABQBkiwAlFxwKXAAdADuwDAxeGnyiiq4sWEJcNIAfHAAjEmp6Vk50XkeUCh8zfkmKgnFcVJllXAATHWpmdm5aUryKOzoLADyJNF2rL1wJfGDVQDMYylpLAAemCgS8sB+LNFJQA

Versions

  • TypeScript version: 5.4.2
  • ts-pattern version: 5.2.0
  • environment: node v18.15.0
exhaustive_readonly_array_1 exhaustive_readonly_array_3 exhaustive_readonly_array_2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants