-
Notifications
You must be signed in to change notification settings - Fork 12.5k
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
Better inline type annotations #13208
Comments
To me, the obvious solution seems to give an error on (But it seems like every time I propose what I believe is the obvious solution around here, someone tells me why it's horribly wrong, so I leave this as a separate comment to not distract from the main proposal 😉 ) |
Something similar in here: #7481 (comment) and #11216 |
I really like @wallverb's suggestion. Also it would not limit this to mapped types. |
also consider #13082 (automated extracting an interface from an object literal) |
@Aleksey-Bykov #13082 is a great but they serve different purposes. Both would be valuable. |
I think #7481 is the preferred answer here |
Say I'm writing some code like this:
I would like
myNestedObject
to understand thatfoo
is type{ [key in MyKeyValues]: number }
, so that the type of myNestedObject is fully inferred. I currently have a few suboptimal solutions:I don't like this because it is a violation of DRY. If I want to add new keys to
myNestedObject
, I have to add them twice.This is nicer on the eyes, but not nicer on the type checker. Now we don't get any error that "d" has been omitted from
foo
.Summary: I would like some of syntax to give a type to the inner object.
The text was updated successfully, but these errors were encountered: