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
|
tests/cases/conformance/expressions/propertyAccess/propertyAccess.ts(11,55): error TS2322: Type '{ 3: string; 'three': string; }' is not assignable to type '{ [n: number]: string; }'.
Object literal may only specify known properties, and ''three'' does not exist in type '{ [n: number]: string; }'.
tests/cases/conformance/expressions/propertyAccess/propertyAccess.ts(45,14): error TS2339: Property 'qqq' does not exist on type '{ 10: string; x: string; y: number; z: { n: string; m: number; o: () => boolean; }; 'literal property': number; }'.
tests/cases/conformance/expressions/propertyAccess/propertyAccess.ts(80,19): error TS2538: Type '{ name: string; }' cannot be used as an index type.
tests/cases/conformance/expressions/propertyAccess/propertyAccess.ts(117,18): error TS2538: Type '{ name: string; }' cannot be used as an index type.
tests/cases/conformance/expressions/propertyAccess/propertyAccess.ts(140,22): error TS2538: Type '{ name: string; }' cannot be used as an index type.
tests/cases/conformance/expressions/propertyAccess/propertyAccess.ts(149,5): error TS2403: Subsequent variable declarations must have the same type. Variable 'x3' must be of type 'A | B', but here has type 'A'.
==== tests/cases/conformance/expressions/propertyAccess/propertyAccess.ts (6 errors) ====
class A {
a: number;
}
class B extends A {
b: number;
}
enum Compass {
North, South, East, West
}
var numIndex: { [n: number]: string } = { 3: 'three', 'three': 'three' };
~~~~~~~~~~~~~~~~
!!! error TS2322: Type '{ 3: string; 'three': string; }' is not assignable to type '{ [n: number]: string; }'.
!!! error TS2322: Object literal may only specify known properties, and ''three'' does not exist in type '{ [n: number]: string; }'.
var strIndex: { [n: string]: Compass } = { 'N': Compass.North, 'E': Compass.East };
var bothIndex:
{
[n: string]: A;
[m: number]: B;
};
function noIndex() { }
var obj = {
10: 'ten',
x: 'hello',
y: 32,
z: { n: 'world', m: 15, o: () => false },
'literal property': 100
};
var anyVar: any = {};
var stringOrNumber: string | number;
var someObject: { name: string };
// Assign to a property access
obj.y = 4;
// Property access on value of type 'any'
anyVar.x = anyVar.y = obj.x = anyVar.z;
// Dotted property access of property that exists
var aa = obj.x;
// Dotted property access of property that exists on value's apparent type
var bb = obj.hasOwnProperty;
// Dotted property access of property that doesn't exist on value's apparent type
var cc = obj.qqq; // error
~~~
!!! error TS2339: Property 'qqq' does not exist on type '{ 10: string; x: string; y: number; z: { n: string; m: number; o: () => boolean; }; 'literal property': number; }'.
// Bracket notation property access using string literal value on type with property of that literal name
var dd = obj['literal property'];
var 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'];
var ee: any;
// Bracket notation property access using numeric string literal value on type with property of that literal name
var ff = obj['10'];
var ff: string;
// Bracket notation property access using numeric string literal value on type without property of that literal name
var gg = obj['1'];
var gg: any;
// Bracket notation property access using numeric value on type with numeric index signature
var hh = numIndex[3.0];
var hh: string;
// Bracket notation property access using enum value on type with numeric index signature
var ii = numIndex[Compass.South];
var ii: string;
// Bracket notation property access using value of type 'any' on type with numeric index signature
var jj = numIndex[anyVar];
var jj: string;
// Bracket notation property access using string value on type with numeric index signature
var kk = numIndex['what'];
var 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
~~~~~~~~~~
!!! error TS2538: Type '{ name: string; }' cannot be used as an index type.
// Bracket notation property access using string value on type with string index signature and no numeric index signature
var mm = strIndex['N'];
var mm: Compass;
var mm2 = strIndex['zzz'];
var mm2: Compass;
// Bracket notation property access using numeric value on type with string index signature and no numeric index signature
var nn = strIndex[10];
var 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];
var 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];
var pp: Compass;
// Bracket notation property access using numeric value on type with no index signatures
var qq = noIndex[123];
var qq: any;
// Bracket notation property access using string value on type with no index signatures
var rr = noIndex['zzzz'];
var rr: any;
// Bracket notation property access using enum value on type with no index signatures
var ss = noIndex[Compass.South];
var ss: any;
// Bracket notation property access using value of type 'any' on type with no index signatures
var tt = noIndex[<any>null];
var tt: any;
// Bracket notation property access using values of other types on type with no index signatures
var uu = noIndex[someObject]; // Error
~~~~~~~~~~
!!! error TS2538: Type '{ name: string; }' cannot be used as an index type.
// Bracket notation property access using numeric value on type with numeric index signature and string index signature
var vv = noIndex[32];
var vv: any;
// Bracket notation property access using enum value on type with numeric index signature and string index signature
var ww = bothIndex[Compass.East];
var 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];
var xx: B;
// Bracket notation property access using string value on type with numeric index signature and string index signature
var yy = bothIndex['foo'];
var 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'];
var 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
~~~~~~~~~~
!!! error TS2538: Type '{ name: string; }' cannot be used as an index type.
var x1 = numIndex[stringOrNumber];
var x1: any;
var x2 = strIndex[stringOrNumber];
var x2: Compass;
var x3 = bothIndex[stringOrNumber];
var x3: A;
~~
!!! error TS2403: Subsequent variable declarations must have the same type. Variable 'x3' must be of type 'A | B', but here has type 'A'.
|