Skip to content
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

Bug in destructuring assignment, losing type analysis information #12263

Closed
tomcumming opened this issue Nov 15, 2016 · 1 comment
Closed

Bug in destructuring assignment, losing type analysis information #12263

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

Comments

@tomcumming
Copy link

tomcumming commented Nov 15, 2016

TypeScript version: 2.0.8

export type State = {
    value: string,
    mode: Selecting | Selected,
}

type Selected = {
    type: 'selected',
    valid: boolean
}

type Selecting = {
    type: 'selecting',
    options: { type: 'loading', handle: number }
        | { type: 'loaded', selection: undefined | number, items: string[] }
}

function f(state: State) {
    if (state.mode.type === 'selecting' && state.mode.options.type === 'loaded') {
        const {options} = state.mode;
        const options2 = state.mode.options;
        options2.items;        
        options.items;
    }
}

Expected
inside f, options and options2 should have the same type

Actual
options loses the narrowed type information

@ahejlsberg
Copy link
Member

Duplicate of #10065 and #10846.

@ahejlsberg ahejlsberg added the Duplicate An existing issue was already created label Nov 15, 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