Skip to content

Enum members aren't subtype reduced in unions #35867

Closed
@DanielRosenwasser

Description

@DanielRosenwasser
enum E {
    A,
    B,
    C,
}

function f(x: E | undefined) {
    return x ?? E.C;
}

Expected f to have type E, but instead it has type E | E.C

Playground

Doesn't have anything to do with ?? - can reproduce it with ||.

enum E {
    A = 1,
    B,
    C,
}

function f(x: E | undefined) {
    return x || E.C;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugA bug in TypeScriptGood First IssueWell scoped, documented and has the green lightHas ReproThis issue has compiler-backed repros: https://aka.ms/ts-reprosHelp WantedYou can do thisInfrastructureIssue relates to TypeScript team infrastructure

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions