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 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428
|
=== tests/cases/conformance/expressions/propertyAccess/propertyAccess.ts ===
class A {
>A : A
a: number;
>a : number
}
class B extends A {
>B : B
>A : A
b: number;
>b : number
}
enum Compass {
>Compass : Compass
North, South, East, West
>North : Compass.North
>South : Compass.South
>East : Compass.East
>West : Compass.West
}
var numIndex: { [n: number]: string } = { 3: 'three', 'three': 'three' };
>numIndex : { [n: number]: string; }
>n : number
>{ 3: 'three', 'three': 'three' } : { 3: string; 'three': string; }
>3 : string
>'three' : "three"
>'three' : string
>'three' : "three"
var strIndex: { [n: string]: Compass } = { 'N': Compass.North, 'E': Compass.East };
>strIndex : { [n: string]: Compass; }
>n : string
>{ 'N': Compass.North, 'E': Compass.East } : { 'N': Compass.North; 'E': Compass.East; }
>'N' : Compass.North
>Compass.North : Compass.North
>Compass : typeof Compass
>North : Compass.North
>'E' : Compass.East
>Compass.East : Compass.East
>Compass : typeof Compass
>East : Compass.East
var bothIndex:
>bothIndex : { [n: string]: A; [m: number]: B; }
{
[n: string]: A;
>n : string
[m: number]: B;
>m : number
};
function noIndex() { }
>noIndex : () => void
var obj = {
>obj : { 10: string; x: string; y: number; z: { n: string; m: number; o: () => boolean; }; 'literal property': number; }
>{ 10: 'ten', x: 'hello', y: 32, z: { n: 'world', m: 15, o: () => false }, 'literal property': 100} : { 10: string; x: string; y: number; z: { n: string; m: number; o: () => boolean; }; 'literal property': number; }
10: 'ten',
>10 : string
>'ten' : "ten"
x: 'hello',
>x : string
>'hello' : "hello"
y: 32,
>y : number
>32 : 32
z: { n: 'world', m: 15, o: () => false },
>z : { n: string; m: number; o: () => boolean; }
>{ n: 'world', m: 15, o: () => false } : { n: string; m: number; o: () => boolean; }
>n : string
>'world' : "world"
>m : number
>15 : 15
>o : () => boolean
>() => false : () => boolean
>false : false
'literal property': 100
>'literal property' : number
>100 : 100
};
var anyVar: any = {};
>anyVar : any
>{} : {}
var stringOrNumber: string | number;
>stringOrNumber : string | number
var someObject: { name: string };
>someObject : { name: string; }
>name : string
// Assign to a property access
obj.y = 4;
>obj.y = 4 : 4
>obj.y : number
>obj : { 10: string; x: string; y: number; z: { n: string; m: number; o: () => boolean; }; 'literal property': number; }
>y : number
>4 : 4
// Property access on value of type 'any'
anyVar.x = anyVar.y = obj.x = anyVar.z;
>anyVar.x = anyVar.y = obj.x = anyVar.z : any
>anyVar.x : any
>anyVar : any
>x : any
>anyVar.y = obj.x = anyVar.z : any
>anyVar.y : any
>anyVar : any
>y : any
>obj.x = anyVar.z : any
>obj.x : string
>obj : { 10: string; x: string; y: number; z: { n: string; m: number; o: () => boolean; }; 'literal property': number; }
>x : string
>anyVar.z : any
>anyVar : any
>z : any
// Dotted property access of property that exists
var aa = obj.x;
>aa : string
>obj.x : string
>obj : { 10: string; x: string; y: number; z: { n: string; m: number; o: () => boolean; }; 'literal property': number; }
>x : string
// Dotted property access of property that exists on value's apparent type
var bb = obj.hasOwnProperty;
>bb : (v: string | number | symbol) => boolean
>obj.hasOwnProperty : (v: string | number | symbol) => boolean
>obj : { 10: string; x: string; y: number; z: { n: string; m: number; o: () => boolean; }; 'literal property': number; }
>hasOwnProperty : (v: string | number | symbol) => boolean
// Dotted property access of property that doesn't exist on value's apparent type
var cc = obj.qqq; // error
>cc : any
>obj.qqq : any
>obj : { 10: string; x: string; y: number; z: { n: string; m: number; o: () => boolean; }; 'literal property': number; }
>qqq : any
// Bracket notation property access using string literal value on type with property of that literal name
var dd = obj['literal property'];
>dd : number
>obj['literal property'] : number
>obj : { 10: string; x: string; y: number; z: { n: string; m: number; o: () => boolean; }; 'literal property': number; }
>'literal property' : "literal property"
var dd: number;
>dd : number
// Bracket notation property access using string literal value on type without property of that literal name
var ee = obj['wa wa wa wa wa'];
>ee : any
>obj['wa wa wa wa wa'] : any
>obj : { 10: string; x: string; y: number; z: { n: string; m: number; o: () => boolean; }; 'literal property': number; }
>'wa wa wa wa wa' : "wa wa wa wa wa"
var ee: any;
>ee : any
// Bracket notation property access using numeric string literal value on type with property of that literal name
var ff = obj['10'];
>ff : string
>obj['10'] : string
>obj : { 10: string; x: string; y: number; z: { n: string; m: number; o: () => boolean; }; 'literal property': number; }
>'10' : "10"
var ff: string;
>ff : string
// Bracket notation property access using numeric string literal value on type without property of that literal name
var gg = obj['1'];
>gg : any
>obj['1'] : any
>obj : { 10: string; x: string; y: number; z: { n: string; m: number; o: () => boolean; }; 'literal property': number; }
>'1' : "1"
var gg: any;
>gg : any
// Bracket notation property access using numeric value on type with numeric index signature
var hh = numIndex[3.0];
>hh : string
>numIndex[3.0] : string
>numIndex : { [n: number]: string; }
>3.0 : 3
var hh: string;
>hh : string
// Bracket notation property access using enum value on type with numeric index signature
var ii = numIndex[Compass.South];
>ii : string
>numIndex[Compass.South] : string
>numIndex : { [n: number]: string; }
>Compass.South : Compass.South
>Compass : typeof Compass
>South : Compass.South
var ii: string;
>ii : string
// Bracket notation property access using value of type 'any' on type with numeric index signature
var jj = numIndex[anyVar];
>jj : string
>numIndex[anyVar] : string
>numIndex : { [n: number]: string; }
>anyVar : any
var jj: string;
>jj : string
// Bracket notation property access using string value on type with numeric index signature
var kk = numIndex['what'];
>kk : any
>numIndex['what'] : any
>numIndex : { [n: number]: string; }
>'what' : "what"
var kk: any;
>kk : any
// Bracket notation property access using value of other type on type with numeric index signature and no string index signature
var ll = numIndex[someObject]; // Error
>ll : any
>numIndex[someObject] : any
>numIndex : { [n: number]: string; }
>someObject : { name: string; }
// Bracket notation property access using string value on type with string index signature and no numeric index signature
var mm = strIndex['N'];
>mm : Compass
>strIndex['N'] : Compass
>strIndex : { [n: string]: Compass; }
>'N' : "N"
var mm: Compass;
>mm : Compass
var mm2 = strIndex['zzz'];
>mm2 : Compass
>strIndex['zzz'] : Compass
>strIndex : { [n: string]: Compass; }
>'zzz' : "zzz"
var mm2: Compass;
>mm2 : Compass
// Bracket notation property access using numeric value on type with string index signature and no numeric index signature
var nn = strIndex[10];
>nn : Compass
>strIndex[10] : Compass
>strIndex : { [n: string]: Compass; }
>10 : 10
var nn: Compass;
>nn : Compass
// Bracket notation property access using enum value on type with string index signature and no numeric index signature
var oo = strIndex[Compass.East];
>oo : Compass
>strIndex[Compass.East] : Compass
>strIndex : { [n: string]: Compass; }
>Compass.East : Compass.East
>Compass : typeof Compass
>East : Compass.East
var oo: Compass;
>oo : Compass
// Bracket notation property access using value of type 'any' on type with string index signature and no numeric index signature
var pp = strIndex[<any>null];
>pp : Compass
>strIndex[<any>null] : Compass
>strIndex : { [n: string]: Compass; }
><any>null : any
>null : null
var pp: Compass;
>pp : Compass
// Bracket notation property access using numeric value on type with no index signatures
var qq = noIndex[123];
>qq : any
>noIndex[123] : any
>noIndex : () => void
>123 : 123
var qq: any;
>qq : any
// Bracket notation property access using string value on type with no index signatures
var rr = noIndex['zzzz'];
>rr : any
>noIndex['zzzz'] : any
>noIndex : () => void
>'zzzz' : "zzzz"
var rr: any;
>rr : any
// Bracket notation property access using enum value on type with no index signatures
var ss = noIndex[Compass.South];
>ss : any
>noIndex[Compass.South] : any
>noIndex : () => void
>Compass.South : Compass.South
>Compass : typeof Compass
>South : Compass.South
var ss: any;
>ss : any
// Bracket notation property access using value of type 'any' on type with no index signatures
var tt = noIndex[<any>null];
>tt : any
>noIndex[<any>null] : any
>noIndex : () => void
><any>null : any
>null : null
var tt: any;
>tt : any
// Bracket notation property access using values of other types on type with no index signatures
var uu = noIndex[someObject]; // Error
>uu : any
>noIndex[someObject] : any
>noIndex : () => void
>someObject : { name: string; }
// Bracket notation property access using numeric value on type with numeric index signature and string index signature
var vv = noIndex[32];
>vv : any
>noIndex[32] : any
>noIndex : () => void
>32 : 32
var vv: any;
>vv : any
// Bracket notation property access using enum value on type with numeric index signature and string index signature
var ww = bothIndex[Compass.East];
>ww : B
>bothIndex[Compass.East] : B
>bothIndex : { [n: string]: A; [m: number]: B; }
>Compass.East : Compass.East
>Compass : typeof Compass
>East : Compass.East
var ww: B;
>ww : B
// Bracket notation property access using value of type 'any' on type with numeric index signature and string index signature
var xx = bothIndex[<any>null];
>xx : B
>bothIndex[<any>null] : B
>bothIndex : { [n: string]: A; [m: number]: B; }
><any>null : any
>null : null
var xx: B;
>xx : B
// Bracket notation property access using string value on type with numeric index signature and string index signature
var yy = bothIndex['foo'];
>yy : A
>bothIndex['foo'] : A
>bothIndex : { [n: string]: A; [m: number]: B; }
>'foo' : "foo"
var yy: A;
>yy : A
// Bracket notation property access using numeric string value on type with numeric index signature and string index signature
var zz = bothIndex['1.0'];
>zz : A
>bothIndex['1.0'] : A
>bothIndex : { [n: string]: A; [m: number]: B; }
>'1.0' : "1.0"
var zz: A;
>zz : A
// Bracket notation property access using value of other type on type with numeric index signature and no string index signature and string index signature
var zzzz = bothIndex[someObject]; // Error
>zzzz : any
>bothIndex[someObject] : any
>bothIndex : { [n: string]: A; [m: number]: B; }
>someObject : { name: string; }
var x1 = numIndex[stringOrNumber];
>x1 : any
>numIndex[stringOrNumber] : any
>numIndex : { [n: number]: string; }
>stringOrNumber : string | number
var x1: any;
>x1 : any
var x2 = strIndex[stringOrNumber];
>x2 : Compass
>strIndex[stringOrNumber] : Compass
>strIndex : { [n: string]: Compass; }
>stringOrNumber : string | number
var x2: Compass;
>x2 : Compass
var x3 = bothIndex[stringOrNumber];
>x3 : A | B
>bothIndex[stringOrNumber] : A | B
>bothIndex : { [n: string]: A; [m: number]: B; }
>stringOrNumber : string | number
var x3: A;
>x3 : A | B
|