Skip to content

default object parameter does not respect optional fields #5289

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

Closed
chadaustin opened this issue Oct 16, 2015 · 1 comment
Closed

default object parameter does not respect optional fields #5289

chadaustin opened this issue Oct 16, 2015 · 1 comment
Labels
Duplicate An existing issue was already created

Comments

@chadaustin
Copy link

This typechecks:

function f({a = 1, b = 2}) {
}
f({});

But this does not:

function f({a = 1, b = 2} = {}) {
}
f();

with an error Type '{}' has no property 'a' and no string index.

I'd expect both to behave the same way.

This idiom is pretty convenient in ES6-style code and I don't see why a passed parameter would be treated differently from a default value here.

@ahejlsberg
Copy link
Member

This is fixed by #4598. The fix is already in the nightly builds and will ship in the 1.7 release.

@ahejlsberg ahejlsberg added the Duplicate An existing issue was already created label Oct 16, 2015
@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
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

2 participants