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 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128
|
=== tests/cases/compiler/noImplicitAnyIndexingSuppressed.ts ===
enum MyEmusEnum {
>MyEmusEnum : MyEmusEnum
emu
>emu : MyEmusEnum.emu
}
// Should be okay; should be a string.
var strRepresentation1 = MyEmusEnum[0]
>strRepresentation1 : string
>MyEmusEnum[0] : string
>MyEmusEnum : typeof MyEmusEnum
>0 : 0
// Should be okay; should be a string.
var strRepresentation2 = MyEmusEnum[MyEmusEnum.emu]
>strRepresentation2 : string
>MyEmusEnum[MyEmusEnum.emu] : string
>MyEmusEnum : typeof MyEmusEnum
>MyEmusEnum.emu : MyEmusEnum
>MyEmusEnum : typeof MyEmusEnum
>emu : MyEmusEnum
// Should be okay, as we suppress implicit 'any' property access checks
var strRepresentation3 = MyEmusEnum["monehh"];
>strRepresentation3 : error
>MyEmusEnum["monehh"] : error
>MyEmusEnum : typeof MyEmusEnum
>"monehh" : "monehh"
// Should be okay; should be a MyEmusEnum
var strRepresentation4 = MyEmusEnum["emu"];
>strRepresentation4 : MyEmusEnum
>MyEmusEnum["emu"] : MyEmusEnum
>MyEmusEnum : typeof MyEmusEnum
>"emu" : "emu"
// Should be okay, as we suppress implicit 'any' property access checks
var x = {}["hi"];
>x : error
>{}["hi"] : error
>{} : {}
>"hi" : "hi"
// Should be okay, as we suppress implicit 'any' property access checks
var y = {}[10];
>y : error
>{}[10] : error
>{} : {}
>10 : 10
var hi: any = "hi";
>hi : any
>"hi" : "hi"
var emptyObj = {};
>emptyObj : {}
>{} : {}
// Should be okay, as we suppress implicit 'any' property access checks
var z1 = emptyObj[hi];
>z1 : error
>emptyObj[hi] : error
>emptyObj : {}
>hi : any
var z2 = (<any>emptyObj)[hi];
>z2 : any
>(<any>emptyObj)[hi] : any
>(<any>emptyObj) : any
><any>emptyObj : any
>emptyObj : {}
>hi : any
interface MyMap<T> {
[key: string]: T;
>key : string
}
var m: MyMap<number> = {
>m : MyMap<number>
>{ "0": 0, "1": 1, "2": 2, "Okay that's enough for today.": NaN} : { "0": number; "1": number; "2": number; "Okay that's enough for today.": number; }
"0": 0,
>"0" : number
>0 : 0
"1": 1,
>"1" : number
>1 : 1
"2": 2,
>"2" : number
>2 : 2
"Okay that's enough for today.": NaN
>"Okay that's enough for today." : number
>NaN : number
};
var mResult1 = m[MyEmusEnum.emu];
>mResult1 : number
>m[MyEmusEnum.emu] : number
>m : MyMap<number>
>MyEmusEnum.emu : MyEmusEnum
>MyEmusEnum : typeof MyEmusEnum
>emu : MyEmusEnum
var mResult2 = m[MyEmusEnum[MyEmusEnum.emu]];
>mResult2 : number
>m[MyEmusEnum[MyEmusEnum.emu]] : number
>m : MyMap<number>
>MyEmusEnum[MyEmusEnum.emu] : string
>MyEmusEnum : typeof MyEmusEnum
>MyEmusEnum.emu : MyEmusEnum
>MyEmusEnum : typeof MyEmusEnum
>emu : MyEmusEnum
var mResult3 = m[hi];
>mResult3 : number
>m[hi] : number
>m : MyMap<number>
>hi : any
|