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

TSError: The inferred type of 'MY_PATTERN' cannot be named without a reference to '<path>/ts-pattern/dist/types/Pattern' #291

Closed
GGomez99 opened this issue Oct 2, 2024 · 3 comments

Comments

@GGomez99
Copy link
Contributor

GGomez99 commented Oct 2, 2024

Describe the bug

When working in a yarn project with many workspaces, and having this compilerOptions in their tsconfig.json:

"compilerOptions": {
   "moduleResolution": "bundler"
}

I get a TS error when I try to directly export a Pattern without explicitly typing its type:

The inferred type of 'MY_PATTERN' cannot be named without a reference to '../.yarn/cache/ts-pattern-npm-5.4.0-2464380e11-f757dd3259.zip/node_modules/ts-pattern/dist/types/Pattern'. This is likely not portable. A type annotation is necessary.

TypeScript playground with a minimal reproduction case

Example: Playground

Versions

  • TypeScript version: 5.6.2
  • ts-pattern version: 5.4.0
  • environment: browser / node version

Possible solutions

In order to solve this, we could:

  1. Directly export the needed types in the package.json of ts-pattern
  2. Put the needed types in a namespace, use it in all the other files and then export that namespace

I think the first solution is the simplest and it won't modify the inferred type names when hovering any ts-pattern functions. The only drawback is that internal types will be exposed through ts-pattern/types but I think that's worth it. I'll make a PR for this!

@lucaschultz
Copy link

Having the same problem; I'm missing the Chainable and GuardP types to be able to create a reusable pattern. @gvergnaud, should I whip up another PR, or is someone already on this?

@lucaschultz
Copy link

lucaschultz commented Oct 13, 2024

Ah, I think I just realized that there hasn't been a release since this PR was merged. That's probably why I'm having the problem.

Edit: I just patched the changes of #292 locally and it works. Looking forward to the next release 🙂

@gvergnaud
Copy link
Owner

@GGomez99 's PR has been published as v5.5.0! Closing this issue

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

3 participants