Skip to content

Object destructuring fails if defaults are set #16355

Closed
@jantimon

Description

@jantimon

TypeScript Version: 2.2.1 / nightly (2.2.0-dev.201xxxxx)
Try it yourself in the playground

Code

function fancyMethod({ option1:boolean = true, option2: number = 1 } = {}) {
    console.log(option1, option2);
}

fancyMethod();
fancyMethod({option2: 3});

Expected behavior:
Console log shows value of option1 and option 2

Actual behavior:
Typescript shows errors:

  • Cannot find name 'option1'.
  • Cannot find name 'option2'.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions