Closed
Description
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
.