Skip to content

Union type is not determined with deep destructuring #12465

Closed
@anvish

Description

@anvish

TypeScript Version: 2.1.1 / nightly (2.2.0-dev.201xxxxx)
2.1.1
Code

type Option = 'a' | { result: number }

type Value = { option: Option }

function do1(value: Value) {
    if (value.option != 'a') {
        const { result } = value.option
    }
}

function do2(value: Value) {
    if (value.option != 'a') {
        const { option: { result } } = value // [ts] Type 'Option' has no property 'result' and no string index signature.
    }
}

Expected behavior:
do2 works as do1, type of value.option is determined
Actual behavior:
do2 works differently from do1, type of value.option is not determined

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