Skip to content

Enum indexer return type should be string|undefined for --strictNullChecks #11140

Closed
@ulrichb

Description

@ulrichb

TypeScript Version: 2.0.3

Code

enum SomeEnum { A = 1, B = 2 }

function lookUp(index: number) {
    return SomeEnum[index].toLowerCase();
}

console.log(lookUp(1)); // => "a"
console.log(lookUp(2)); // => "b"
console.log(lookUp(3)); // => runtime error: "SomeEnum[index] is undefined"

Expected behavior:
When using --strictNullChecks, TSC should emit a compile-time error in lookUp() because there is no undefined-check. => Indexer return type should be string|undefined instead of just string.

Metadata

Metadata

Assignees

No one assigned

    Labels

    DuplicateAn existing issue was already created

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions