-
Notifications
You must be signed in to change notification settings - Fork 12.8k
suggest in
operator when accessing non-common property of union types
#45211
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
Comments
I just realized you suggest a different error message pointing to the But I'd like to point out that the |
Yeah, I saw that tweet and was pretty horrified at all the responses that said to use |
You're right. I should have proposed a better error message instead of a specific fix that may be wrong. We can probably learn something from rust. |
Here's what I would propose (not promising to take a PR on this, just my own opinion):
|
cc @DanielRosenwasser for feedback on that |
I would also suggest suggesting "Try adding This is sound and simple. |
🔍 Search Terms
access to non-common property of union types, suggest in operator for union types
✅ Viability Checklist
My suggestion meets these guidelines:
⭐ Suggestion
Background: https://twitter.com/kentcdodds/status/1420125238436655104?s=21
When accessing props that are not on all union types, tsc gives
Property 'foo' does not exist on type 'XX'
, which is confusing to newcomers. We can suggest thein
operator when it is used insideif
condition.📃 Motivating Example
💻 Use Cases
The text was updated successfully, but these errors were encountered: