Skip to content
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

Merged
merged 8 commits into from
Dec 1, 2016

Conversation

sandersn
Copy link
Member

@sandersn sandersn commented Nov 29, 2016

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.

This is more correct than any and the code is more elegant as well.
@sandersn sandersn changed the title Rest of untyped binding pattern is any Rest of untyped binding pattern is { [s: string]: any } Nov 30, 2016
@@ -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;
Copy link
Contributor

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.

Copy link
Contributor

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.

Copy link
Member Author

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.

Copy link
Member Author

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.

@mhegazy
Copy link
Contributor

mhegazy commented Nov 30, 2016

I think this looks much better.

@mhegazy
Copy link
Contributor

mhegazy commented Nov 30, 2016

@ahejlsberg any comments?

@sandersn sandersn changed the title Rest of untyped binding pattern is { [s: string]: any } Rest of untyped binding pattern is any Nov 30, 2016
@sandersn sandersn changed the title Rest of untyped binding pattern is any Rest of untyped binding pattern is { [s: string]: any } Dec 1, 2016
@sandersn sandersn merged commit fc1f6e3 into master Dec 1, 2016
@sandersn sandersn deleted the rest-of-untyped-binding-pattern-is-any branch December 1, 2016 01:39
@mhegazy mhegazy mentioned this pull request Dec 1, 2016
@microsoft microsoft locked and limited conversation to collaborators Jun 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Object rest destructuring parameter defaults to empty object, causing errors when untyped
3 participants