Skip to content

control flow narrowing is broken in nightly build #10228

Closed

Description

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);
    }
}

Activity

  1. zpdDG4gta8XKpMCd commented on Aug 9, 2016

    @zpdDG4gta8XKpMCd
    Author

    undefined, void and null if it matters

  2. ahejlsberg commented on Aug 9, 2016

    @ahejlsberg
    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.

  3. added this to the milestone on Aug 9, 2016
  4. zpdDG4gta8XKpMCd commented on Aug 11, 2016

    @zpdDG4gta8XKpMCd
    Author

    works, thanks!

  5. locked and limited conversation to collaborators on Jun 19, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

BugA bug in TypeScriptFixedA PR has been merged for this issue

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions