Skip to content

Rest of untyped binding pattern is { [s: string]: any } - #12564

Merged
Nathan Shively-Sanders (sandersn) merged 8 commits into
masterfrom
rest-of-untyped-binding-pattern-is-any
Dec 1, 2016
Merged

Rest of untyped binding pattern is { [s: string]: any }#12564
Nathan Shively-Sanders (sandersn) merged 8 commits into
masterfrom
rest-of-untyped-binding-pattern-is-any

Conversation

@sandersn

@sandersn Nathan Shively-Sanders (sandersn) commented Nov 29, 2016

Copy link
Copy Markdown
Member

Fixes #12519

Edit:
Mohamed Hegazy (@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.

@sandersn Nathan Shively-Sanders (sandersn) changed the title Rest of untyped binding pattern is any Rest 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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Contributor

I think this looks much better.

@mhegazy

Copy link
Copy Markdown
Contributor

Anders Hejlsberg (@ahejlsberg) any comments?

@sandersn Nathan Shively-Sanders (sandersn) changed the title Rest of untyped binding pattern is { [s: string]: any } Rest of untyped binding pattern is any Nov 30, 2016
@sandersn Nathan Shively-Sanders (sandersn) changed the title Rest of untyped binding pattern is any Rest of untyped binding pattern is { [s: string]: any } Dec 1, 2016
@sandersn
Nathan Shively-Sanders (sandersn) deleted the rest-of-untyped-binding-pattern-is-any branch December 1, 2016 01:39
@microsoft 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