Skip to content

Switch on enum of one member not considered exhaustive #12771

Closed
@hmaurer

Description

@hmaurer

TypeScript Version: 2.1.4

Code:

// --strictNullChecks

enum Enum1 {
    A,
    B
}

enum Enum2 {
    A
}


interface Foo {
    readonly kind: Enum1
}

interface Bar {
    readonly kind: Enum2
}

let f = (x: Foo): number => {
    switch (x.kind) {
        case Enum1.A:
            return 1;
        case Enum1.B:
            return 2;
    }
}

let g = (x: Bar): number => {
    switch (x.kind) {
        case Enum2.A:
            return 1;
    }
}

Expected behaviour (as far as I know):

Compiles without error

Actual behaviour:

Function g does not compile, with error TS2366: Function lacks ending return statement and return type does not include 'undefined'..

Without strict null checks, it compiles without error.

Metadata

Metadata

Assignees

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