-
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
Rest of untyped binding pattern is { [s: string]: any } #12564
Conversation
This is more correct than any and the code is more elegant as well.
@@ -36,3 +36,5 @@ let computed = 'b'; | |||
let computed2 = 'a'; | |||
var { [computed]: stillNotGreat, [computed2]: soSo, ...o } = o; | |||
({ [computed]: stillNotGreat, [computed2]: soSo, ...o } = o); | |||
|
|||
var noContextualType = ({ aNumber = 12, ...notEmptyObject }) => aNumber; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you add a test where notEmptyObject.somePropoerty is used, to make sure we get an error if the behavior changes, instead of just the type-baseline changes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
also can you add a test for --noImplicitAny
error for this case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wait—actually this doesn't allow arbitrary access to properties, just indexed access.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, so I added back the special case. Which makes the two tests you asked for pass.
I think this looks much better. |
@ahejlsberg any comments? |
Fixes #12519
Edit:
@mhegazy pointed out that (1) rest of an untyped binding pattern isn't really any since it's definitely not a function (2) adding an index signature results in a more straightforward fix. So the current version adds an index signature to the structurally inferred type of an untyped binding pattern.