10000 default object parameter does not respect optional fields · Issue #5289 · microsoft/TypeScript · GitHub
[go: up one dir, main page]

Skip to content
default object parameter does not respect optional fields #5289
@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
    < 3137 div data-testid="sidebar-section" class="Box-sc-g0xbh4-0 flElOg Section-module__SectionContainer--jjjKt">

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0