mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-15 12:51:30 -05:00
Merge pull request #49912 from microsoft/fix/47508
fix(47508): noUncheckedIndexedAccess with enums Type narrowed
This commit is contained in:
30
tests/cases/compiler/noUncheckedIndexAccess.ts
Normal file
30
tests/cases/compiler/noUncheckedIndexAccess.ts
Normal 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];
|
||||
Reference in New Issue
Block a user