Skip to content

narrowing doesn't work for literal strings in switch when united with unconstrained string #10417

@zpdDG4gta8XKpMCd

Description

@zpdDG4gta8XKpMCd

nightly build, August 18, 2016

function useA(value: 'a'): void { }
function useB(value: 'b'): void { }
function useSomethingElse(value: string): void { }
declare var kind: string | 'a' | 'b';
switch (kind) {
    case 'a': useA(kind); break; // expected kind to be 'a', actual 'a' | string
    case 'b': useB(kind); break;
    default: useSomethingElse(kind); break;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    FixedA PR has been merged for this issueSuggestionAn idea for TypeScript

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions