File: noImplicitAnyIndexingSuppressed.types

package info (click to toggle)
node-typescript 5.2.2-1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 497,488 kB
  • sloc: javascript: 2,107,274; makefile: 6; sh: 1
file content (130 lines) | stat: -rw-r--r-- 2,867 bytes parent folder | download
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
129
130
//// [tests/cases/compiler/noImplicitAnyIndexingSuppressed.ts] ////

=== 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 : any
>MyEmusEnum["monehh"] : any
>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 : undefined
>{}["hi"] : undefined
>{} : {}
>"hi" : "hi"

// Should be okay, as we suppress implicit 'any' property access checks
var y = {}[10];
>y : undefined
>{}[10] : undefined
>{} : {}
>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 : any
>emptyObj[hi] : any
>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