Skip to content

Control flow based analysis type guard failed on negative narrowing test #10061

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
vilicvane opened this issue Aug 1, 2016 · 2 comments
Closed
Labels
External Relates to another program, environment, or user action which we cannot control.

Comments

@vilicvane
Copy link

TypeScript Version: nightly (2.1.0-dev.20160731)

Related to (duplicte of) #9861

Code

function foo(value: string | number) {
    if (typeof value !== 'string') {
        return;
    } else {
        // value here has type string.
    }

    // value here has type string | number.
}

Expected behavior:

Both value in else and the rest of the function should be narrowed to string.

Actual behavior:

Only value in else is narrowed.

@yortus
Copy link
Contributor

yortus commented Aug 1, 2016

I can't reproduce this in 2.1.0-dev.20160731. This is what I see:

function foo(value: string | number) {
    if (typeof value !== 'string') {
        value // value is number
        return;
    } else {
        value // value is string
    }

    value // value is string
}

@vilicvane
Copy link
Author

Strange then, can't reproduce it myself. Might be some misconfiguration.

@RyanCavanaugh RyanCavanaugh added the External Relates to another program, environment, or user action which we cannot control. label Aug 1, 2016
@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
External Relates to another program, environment, or user action which we cannot control.
Projects
None yet
Development

No branches or pull requests

3 participants