-
Notifications
You must be signed in to change notification settings - Fork 463
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
Confusing type errors / warning when using optional record fields #5953
Comments
This is indeed expected behavior. You would need to do let {count, ?username} = props This is documented here: https://rescript-lang.org/docs/manual/latest/record#pattern-matching-on-optional-fields I agree that it feels quite unexpected when destructuring. It tripped me up, too, when I first encountered it. |
Maybe we can help out here and automatically insert |
We should also probably document an actual destructure, the docs has switches only. |
Fixed in the editor tooling in rescript-lang/rescript-vscode#715 |
IMO if this is the only way an optional attr should be destructured, then it should be enforced on the type checker level. Everything else seems hacky to me. |
This is not about optional args. You can as well write |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
Here's an example on different confusing errors / warnings:
I think it all boils down to the fact that the initial props destructing doesn't really do what I actually expected.
Is this expected behavior?
The text was updated successfully, but these errors were encountered: