Skip to content

narrowing in switch doesn't work with non-union types #16976

Open
@zpdDG4gta8XKpMCd

Description

@zpdDG4gta8XKpMCd
class A {
    readonly kind = 'a';
}
type U = A; // <-- supposed to be a single case union
declare var u: U;
declare function never(never: never): never;
function fn() {
    switch (u.kind) {
        case 'a': return 1;
        default: return never(u); // <-- u expected to be never, actually is A
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    In DiscussionNot yet reached consensusSuggestionAn idea for TypeScript

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions