Skip to content

default object parameter does not respect optional fields #5289

Closed
@chadaustin

Description

@chadaustin

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    DuplicateAn existing issue was already created

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions