-
-
Notifications
You must be signed in to change notification settings - Fork 129
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
Array element matching bug on empty arrays #46
Comments
I agree this behavior is confusing, but it's expected. In retrospect, I don't think this was a great API choice because it can be confused with an unary tuple pattern (a pattern matching a list with a single element). I've been thinking about introducing a separate import { match, list, __ } from 'ts-pattern';
match(someList)
.with([], () => 'empty list')
.with([__], () => 'list with a single element')
.with(list(not(null)), () => 'list with n elements')
.exhaustive(); But this would be a breaking change, which makes it a bit tricky to release. |
It would be tricky indeed 🤔 That said, it would be more intuitive, IMO. Maybe for ts-pattern v4 🥳 ? |
Closing since TS-Pattern v4 has been released and fixes this problem. Release note |
Hi !
Describe the bug
Even if the first is a bit ambiguous, I would at least expect the second one NOT to print "first"...
Code Sandbox with a minimal reproduction case
https://codesandbox.io/s/icy-glade-3ty9l?file=/src/index.ts
Versions
The text was updated successfully, but these errors were encountered: