Skip to content

Union type is not determined with deep destructuring #12465

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
anvish opened this issue Nov 23, 2016 · 1 comment
Closed

Union type is not determined with deep destructuring #12465

anvish opened this issue Nov 23, 2016 · 1 comment
Labels
Duplicate An existing issue was already created

Comments

@anvish
Copy link

anvish commented Nov 23, 2016

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

@ahejlsberg
Copy link
Member

Duplicate of #10065 and #10846.

@ahejlsberg ahejlsberg added the Duplicate An existing issue was already created label Nov 23, 2016
@mhegazy mhegazy closed this as completed Apr 21, 2017
@microsoft microsoft locked and limited conversation to collaborators Jun 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

3 participants