Skip to content

Typescript does not work with defaults #16354

Closed
@jantimon

Description

@jantimon

TypeScript Version: 2.2.1 / nightly (2.2.0-dev.201xxxxx)
Try it yourself using this Playground Link

Code

    function fancyMethod({ option1 = true }: { option1?: boolean } = {}) {
        console.log(option1);
    }
    
    fancyMethod("abc");
    fancyMethod(false);
    fancyMethod(42);

Expected behavior:

Typescript will let me know that "abc" or false or 42 are not of type { option1?: boolean }.

Actual behavior:

No type error is shown

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