Merge pull request #49912 from microsoft/fix/47508

fix(47508): noUncheckedIndexedAccess with enums Type narrowed
This commit is contained in:
navya9singh
2022-09-26 09:47:33 -07:00
committed by GitHub
5 changed files with 274 additions and 1 deletions

View File

@@ -0,0 +1,30 @@
//@noUncheckedIndexedAccess: true
//@strictNullChecks: true
enum Meat {
Sausage,
Bacon
}
const sausage = Meat.Sausage
const valueSausage = Meat[sausage]
const bacon = Meat.Bacon
const valueBacon = Meat[bacon]
const union: Meat.Bacon | Meat.Sausage = Meat.Bacon
const valueUnion = Meat[union]
//Avoiding a false positive
const value = Meat[0]
const valueUndefined = "testing"
const value2 = Meat[valueUndefined]
enum A {
a, b, c
}
enum B {
x, y, z
}
const value3 = A[B.x];