Skip to content

Mutually exclusive guard constraints and 'never' #9869

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
zhuravlikjb opened this issue Jul 21, 2016 · 3 comments
Closed

Mutually exclusive guard constraints and 'never' #9869

zhuravlikjb opened this issue Jul 21, 2016 · 3 comments
Labels
Working as Intended The behavior described is the intended behavior; this is not a bug

Comments

@zhuravlikjb
Copy link

Applying two mutually exclusive guard constraints doesn't lead to 'never' type in the following case:

function ololo() {
    let stringOrNumber: string | number = 3 > 5 ? "a" : 7;

    if (typeof stringOrNumber === "number") {
        if (typeof stringOrNumber !== "number") {
            stringOrNumber; // shouldn't this be 'never'?
        }
    } 

Seems that it should.

@yahiko00
Copy link

Intellisense (TS 2.0.0) tells the innermost stringOrNumber is a string.

@kitsonk
Copy link
Contributor

kitsonk commented Jul 21, 2016

I mean you could argue that, but at the same time when the code is illogical and unreachable at run-time, why would you expect the control flow to work? What benefit would there be in coding for that?

@ahejlsberg
Copy link
Member

This is working as intended as per #8548. There are a number of subtle issues interacting here and we haven't come up with a better place to land yet.

@ahejlsberg ahejlsberg added the Working as Intended The behavior described is the intended behavior; this is not a bug label Jul 21, 2016
@mhegazy mhegazy closed this as completed Jul 21, 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
Working as Intended The behavior described is the intended behavior; this is not a bug
Projects
None yet
Development

No branches or pull requests

5 participants