Skip to content

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

@rikutiira

Description

@rikutiira

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions