Skip to content

Conversation

@sandersn
Copy link
Member

@sandersnsandersn 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.
@sandersnsandersn changed the title Rest of untyped binding pattern is anyRest of untyped binding pattern is{[s: string]: any }Nov 30, 2016
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
MemberAuthor

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
MemberAuthor

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

I think this looks much better.

@mhegazy
Copy link
Contributor

@ahejlsberg any comments?

@sandersnsandersn changed the title Rest of untyped binding pattern is{[s: string]: any }Rest of untyped binding pattern is anyNov 30, 2016
@sandersnsandersn changed the title Rest of untyped binding pattern is anyRest of untyped binding pattern is{[s: string]: any }Dec 1, 2016
@sandersnsandersn merged commit fc1f6e3 into masterDec 1, 2016
@sandersnsandersn deleted the rest-of-untyped-binding-pattern-is-any branch December 1, 2016 01:39
@mhegazymhegazy mentioned this pull request Dec 1, 2016
@microsoftmicrosoft locked and limited conversation to collaborators Jun 19, 2018
Sign up for freeto 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

4 participants

@sandersn@mhegazy@msftclas