1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
|
=== tests/cases/compiler/noUncheckedIndexAccess.ts ===
enum Meat {
>Meat : Meat
Sausage,
>Sausage : Meat.Sausage
Bacon
>Bacon : Meat.Bacon
}
const sausage = Meat.Sausage
>sausage : Meat.Sausage
>Meat.Sausage : Meat.Sausage
>Meat : typeof Meat
>Sausage : Meat.Sausage
const valueSausage = Meat[sausage]
>valueSausage : string
>Meat[sausage] : string
>Meat : typeof Meat
>sausage : Meat.Sausage
const bacon = Meat.Bacon
>bacon : Meat.Bacon
>Meat.Bacon : Meat.Bacon
>Meat : typeof Meat
>Bacon : Meat.Bacon
const valueBacon = Meat[bacon]
>valueBacon : string
>Meat[bacon] : string
>Meat : typeof Meat
>bacon : Meat.Bacon
const union: Meat.Bacon | Meat.Sausage = Meat.Bacon
>union : Meat
>Meat : any
>Meat : any
>Meat.Bacon : Meat.Bacon
>Meat : typeof Meat
>Bacon : Meat.Bacon
const valueUnion = Meat[union]
>valueUnion : string
>Meat[union] : string
>Meat : typeof Meat
>union : Meat.Bacon
//Avoiding a false positive
const value = Meat[0]
>value : string | undefined
>Meat[0] : string | undefined
>Meat : typeof Meat
>0 : 0
const valueUndefined = "testing"
>valueUndefined : "testing"
>"testing" : "testing"
const value2 = Meat[valueUndefined]
>value2 : error
>Meat[valueUndefined] : error
>Meat : typeof Meat
>valueUndefined : "testing"
enum A {
>A : A
a, b, c
>a : A.a
>b : A.b
>c : A.c
}
enum B {
>B : B
x, y, z
>x : B.x
>y : B.y
>z : B.z
}
const value3 = A[B.x];
>value3 : string | undefined
>A[B.x] : string | undefined
>A : typeof A
>B.x : B.x
>B : typeof B
>x : B.x
|