-
Notifications
You must be signed in to change notification settings - Fork 12.4k
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
Improve error message for union indexing #30241
Comments
If the indexing type is or is a union containing a literal type, we can provide a better error message. |
@DanielRosenwasser Can I work on this one? |
Go for it, but make sure it makes sense for a single-element string, and a union of string literals, and a union of string literals + a non-indexable member. |
@DanielRosenwasser It's probably too late for this to make it into 3.5, but I would really appreciate it if you could review it the PR when you get a chance. I want to make any required changes until 3.5 is released so this is ready to be merged when the dev cycle for 3.6 starts. Thank you. |
Thanks @dragomirtitian! |
@DanielRosenwasser My pleasure, it was fun 😊 |
Thank you very much for addressing my issue! 😎 |
Search Terms
union, index
Suggestion
When a type union is used to index into a type with no index signature, if the property names match up correctly the access is allowed and Typescript does the "right thing" anyway. If the property names don't match up, and there's no index signature, an error is given, but it might not be the most helpful error.
Use Cases
I have a type that's a union of string literals, and I want to create some mapping for them. But if I forget a single property name, the error doesn't help me find what was missing
Examples
Related
#14951
Checklist
My suggestion meets these guidelines:
The text was updated successfully, but these errors were encountered: