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:
- Directly export the needed types in the
package.json of ts-pattern
- 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!