Skip to content

control flow narrowing is broken in nightly build #10228

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
zpdDG4gta8XKpMCd opened this issue Aug 9, 2016 · 3 comments
Closed

control flow narrowing is broken in nightly build #10228

zpdDG4gta8XKpMCd opened this issue Aug 9, 2016 · 3 comments
Assignees
Labels
Bug A bug in TypeScript Fixed A PR has been merged for this issue

Comments

@zpdDG4gta8XKpMCd
Copy link

zpdDG4gta8XKpMCd commented Aug 9, 2016

nightly build August 9, 2016

the following used to work in July 30 build

interface A { kind: 'A'; }
interface B { kind: 'B'; }

type C = A | B | undefined;

function never(_: never): never {
    throw new Error();
}

function useA(_: A): void {
}
function useB(_: B): void {
}
declare var c: C;

if (c === undefined) {
} else {
    switch (c.kind) {
        // below expected: narrowing to work, actual: doesn't work:
        case 'A': useA(c); break;
        case 'B': useB(c); break;
        default: never(c);
    }
}
@zpdDG4gta8XKpMCd
Copy link
Author

undefined, void and null if it matters

@ahejlsberg
Copy link
Member

This is caused by the stricter discriminant property check introduced in #10188. It's an easy fix, we just need to ignore undefined, null, and void in the declared type when checking whether a property in a particular declared type is a discriminant property. I will put up a fix later today.

@RyanCavanaugh RyanCavanaugh added the Bug A bug in TypeScript label Aug 9, 2016
@ahejlsberg ahejlsberg added this to the TypeScript 2.0.1 milestone Aug 9, 2016
@ahejlsberg ahejlsberg added the Fixed A PR has been merged for this issue label Aug 10, 2016
@zpdDG4gta8XKpMCd
Copy link
Author

works, thanks!

@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
Bug A bug in TypeScript Fixed A PR has been merged for this issue
Projects
None yet
Development

No branches or pull requests

3 participants