-
-
Notifications
You must be signed in to change notification settings - Fork 114
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
Select produces wrong types #172
Comments
Hey, First, here is a workaround: you can use const useStatePattern = { ... } as const;
match<any, any>({})
.with(useStatePattern, (selections) =>
/* selections: {
value: Object;
stateIdentifier: string;
setStateIdentifier: string;
typeParameters: Object | undefined;
} */
)
.otherwise(() => null); It doesn't work without it because TypeScript will infer the type of arrays contained inside match<any, any>({})
.with({ /* ... your useStatePattern inlined */ }, (selections) => selections) // would work
.otherwise(() => null) as any; That said, I think we should change the |
Thanks for the answer, the workaround works fine for my use case |
It turns out that part of this bug is due to what I believe is a bug in the type checker when deduplicating arrays elements that use phantom type parameters: Playground I'm planning to open an issue on TypeScript's repository, keeping this issue open in the meantime. |
Hi, I'm trying to extract
useState
patterns from react, but theselections
object has the wrong types (some properties aren't even added):Using the latest version as of today
"ts-pattern": "^5.0.1"
The text was updated successfully, but these errors were encountered: