Skip to content

Commit de465ad

Browse files
committed
Add more tests
1 parent 6225c77 commit de465ad

File tree

3 files changed

+86
-51
lines changed

3 files changed

+86
-51
lines changed

tests/baselines/reference/indexSignatureTypeCheck.errors.txt

Lines changed: 39 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
1-
tests/cases/compiler/indexSignatureTypeCheck.ts(35,1): error TS2342: An index expression argument must be of type 'string', 'number', 'symbol, or 'any'.
2-
tests/cases/compiler/indexSignatureTypeCheck.ts(38,8): error TS1019: An index signature parameter cannot have a question mark.
3-
tests/cases/compiler/indexSignatureTypeCheck.ts(39,6): error TS1017: An index signature cannot have a rest parameter.
1+
tests/cases/compiler/indexSignatureTypeCheck.ts(34,1): error TS2342: An index expression argument must be of type 'string', 'number', 'symbol, or 'any'.
2+
tests/cases/compiler/indexSignatureTypeCheck.ts(37,8): error TS1019: An index signature parameter cannot have a question mark.
3+
tests/cases/compiler/indexSignatureTypeCheck.ts(38,6): error TS1017: An index signature cannot have a rest parameter.
4+
tests/cases/compiler/indexSignatureTypeCheck.ts(39,6): error TS1096: An index signature must have exactly one parameter.
45
tests/cases/compiler/indexSignatureTypeCheck.ts(40,6): error TS1096: An index signature must have exactly one parameter.
5-
tests/cases/compiler/indexSignatureTypeCheck.ts(41,6): error TS1096: An index signature must have exactly one parameter.
6-
tests/cases/compiler/indexSignatureTypeCheck.ts(51,2): error TS2375: Duplicate number index signature.
7-
tests/cases/compiler/indexSignatureTypeCheck.ts(56,2): error TS2375: Duplicate number index signature.
8-
tests/cases/compiler/indexSignatureTypeCheck.ts(64,1): error TS2322: Type '{ [x: number]: string; }' is not assignable to type '{ [x: string]: string; }'.
6+
tests/cases/compiler/indexSignatureTypeCheck.ts(50,5): error TS2375: Duplicate number index signature.
7+
tests/cases/compiler/indexSignatureTypeCheck.ts(55,5): error TS2375: Duplicate number index signature.
8+
tests/cases/compiler/indexSignatureTypeCheck.ts(65,1): error TS2322: Type '{ [x: number]: string; }' is not assignable to type '{ [x: string]: string; }'.
99
Index signature is missing in type '{ [x: number]: string; }'.
10-
tests/cases/compiler/indexSignatureTypeCheck.ts(65,1): error TS2322: Type '{ [x: number]: number; }' is not assignable to type '{ [x: string]: string; }'.
10+
tests/cases/compiler/indexSignatureTypeCheck.ts(66,1): error TS2322: Type '{ [x: number]: number; }' is not assignable to type '{ [x: string]: string; }'.
1111
Index signature is missing in type '{ [x: number]: number; }'.
12-
tests/cases/compiler/indexSignatureTypeCheck.ts(69,1): error TS2322: Type '{ [x: number]: number; }' is not assignable to type '{ [x: number]: string; }'.
12+
tests/cases/compiler/indexSignatureTypeCheck.ts(70,1): error TS2322: Type '{ [x: number]: number; }' is not assignable to type '{ [x: number]: string; }'.
1313
Index signatures are incompatible.
1414
Type 'number' is not assignable to type 'string'.
15-
tests/cases/compiler/indexSignatureTypeCheck.ts(71,1): error TS2322: Type '{ [x: string]: string; }' is not assignable to type '{ [x: number]: number; }'.
15+
tests/cases/compiler/indexSignatureTypeCheck.ts(72,1): error TS2322: Type '{ [x: string]: string; }' is not assignable to type '{ [x: number]: number; }'.
1616
Index signatures are incompatible.
1717
Type 'string' is not assignable to type 'number'.
18-
tests/cases/compiler/indexSignatureTypeCheck.ts(72,1): error TS2322: Type '{ [x: number]: string; }' is not assignable to type '{ [x: number]: number; }'.
18+
tests/cases/compiler/indexSignatureTypeCheck.ts(73,1): error TS2322: Type '{ [x: number]: string; }' is not assignable to type '{ [x: number]: number; }'.
1919
Index signatures are incompatible.
2020
Type 'string' is not assignable to type 'number'.
2121

@@ -29,31 +29,30 @@ tests/cases/compiler/indexSignatureTypeCheck.ts(72,1): error TS2322: Type '{ [x:
2929
var index: any = "hello";
3030
ps[index] = 12;
3131

32-
enum Val {
32+
enum Values {
3333
a = 1,
3434
b = 2
3535
}
3636

37-
type Val2 = Val;
38-
type Val3 = number;
37+
type Values2 = Values;
38+
type Values3 = number;
3939

40-
interface IEnum {
41-
[index: Val]: Val;
40+
interface EnumMap {
41+
[index: Values]: Values;
4242
}
4343

44-
45-
interface IEnum2 {
46-
[index: Val2]: Val2;
44+
interface EnumMap2 {
45+
[index: Values2]: Values2;
4746
}
48-
interface IEnum3 {
49-
[index: Val3]: Val3;
47+
interface NumberMap {
48+
[index: Values3]: Values3;
5049
}
5150

52-
var pe: IEnum = null;
51+
var pe: Values = null;
5352

5453
pe[1] = null
5554
pe[3] = null
56-
pe[Val.b] = 5
55+
pe[Values.b] = 5
5756

5857
pe[true] = null
5958
~~~~~~~~
@@ -80,21 +79,23 @@ tests/cases/compiler/indexSignatureTypeCheck.ts(72,1): error TS2322: Type '{ [x:
8079

8180

8281
interface DuplicateAccess {
83-
[index: Val]: Val;
84-
[index: Val2]: Val2;
85-
~~~~~~~~~~~~~~~~~~~~
82+
[index: Values]: Values;
83+
[index: Values2]: Values2;
84+
~~~~~~~~~~~~~~~~~~~~~~~~~~
8685
!!! error TS2375: Duplicate number index signature.
8786
}
8887

8988
interface DuplicateAccess2 {
90-
[index: number]: Val;
91-
[index: Val3]: Val3;
92-
~~~~~~~~~~~~~~~~~~~~
89+
[index: number]: Values;
90+
[index: Values3]: Values3;
91+
~~~~~~~~~~~~~~~~~~~~~~~~~~
9392
!!! error TS2375: Duplicate number index signature.
9493
}
9594

9695
var x: { [x: string]: string }
96+
var xn: {[x: string]: number }
9797
var y: { [x: number]: string }
98+
var yn: { [x: number]: number }
9899
var z: { [x: E]: number }
99100

100101
x = x;
@@ -126,5 +127,14 @@ tests/cases/compiler/indexSignatureTypeCheck.ts(72,1): error TS2322: Type '{ [x:
126127
!!! error TS2322: Index signatures are incompatible.
127128
!!! error TS2322: Type 'string' is not assignable to type 'number'.
128129
z = z;
130+
z = yn;
131+
z = xn;
132+
133+
// TODO: Should fail
134+
yn = z;
129135

136+
type foo = string
137+
var s: { [x: foo]: string }
138+
x = s
139+
s = x
130140

tests/baselines/reference/indexSignatureTypeCheck.js

Lines changed: 41 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -7,31 +7,30 @@ var ps: IPropertySet = null;
77
var index: any = "hello";
88
ps[index] = 12;
99

10-
enum Val {
10+
enum Values {
1111
a = 1,
1212
b = 2
1313
}
1414

15-
type Val2 = Val;
16-
type Val3 = number;
15+
type Values2 = Values;
16+
type Values3 = number;
1717

18-
interface IEnum {
19-
[index: Val]: Val;
18+
interface EnumMap {
19+
[index: Values]: Values;
2020
}
2121

22-
23-
interface IEnum2 {
24-
[index: Val2]: Val2;
22+
interface EnumMap2 {
23+
[index: Values2]: Values2;
2524
}
26-
interface IEnum3 {
27-
[index: Val3]: Val3;
25+
interface NumberMap {
26+
[index: Values3]: Values3;
2827
}
2928

30-
var pe: IEnum = null;
29+
var pe: Values = null;
3130

3231
pe[1] = null
3332
pe[3] = null
34-
pe[Val.b] = 5
33+
pe[Values.b] = 5
3534

3635
pe[true] = null
3736

@@ -48,17 +47,19 @@ enum E {
4847

4948

5049
interface DuplicateAccess {
51-
[index: Val]: Val;
52-
[index: Val2]: Val2;
50+
[index: Values]: Values;
51+
[index: Values2]: Values2;
5352
}
5453

5554
interface DuplicateAccess2 {
56-
[index: number]: Val;
57-
[index: Val3]: Val3;
55+
[index: number]: Values;
56+
[index: Values3]: Values3;
5857
}
5958

6059
var x: { [x: string]: string }
60+
var xn: {[x: string]: number }
6161
var y: { [x: number]: string }
62+
var yn: { [x: number]: number }
6263
var z: { [x: E]: number }
6364

6465
x = x;
@@ -72,22 +73,31 @@ y = z;
7273
z = x;
7374
z = y;
7475
z = z;
76+
z = yn;
77+
z = xn;
78+
79+
// TODO: Should fail
80+
yn = z;
7581

82+
type foo = string
83+
var s: { [x: foo]: string }
84+
x = s
85+
s = x
7686

7787

7888
//// [indexSignatureTypeCheck.js]
7989
var ps = null;
8090
var index = "hello";
8191
ps[index] = 12;
82-
var Val;
83-
(function (Val) {
84-
Val[Val["a"] = 1] = "a";
85-
Val[Val["b"] = 2] = "b";
86-
})(Val || (Val = {}));
92+
var Values;
93+
(function (Values) {
94+
Values[Values["a"] = 1] = "a";
95+
Values[Values["b"] = 2] = "b";
96+
})(Values || (Values = {}));
8797
var pe = null;
8898
pe[1] = null;
8999
pe[3] = null;
90-
pe[Val.b] = 5;
100+
pe[Values.b] = 5;
91101
pe[true] = null;
92102
var E;
93103
(function (E) {
@@ -96,7 +106,9 @@ var E;
96106
E[E["C"] = 2] = "C";
97107
})(E || (E = {}));
98108
var x;
109+
var xn;
99110
var y;
111+
var yn;
100112
var z;
101113
x = x;
102114
x = y;
@@ -107,3 +119,10 @@ y = z;
107119
z = x;
108120
z = y;
109121
z = z;
122+
z = yn;
123+
z = xn;
124+
// TODO: Should fail
125+
yn = z;
126+
var s;
127+
x = s;
128+
s = x;

tests/cases/compiler/indexSignatureTypeCheck.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,9 @@ interface DuplicateAccess2 {
5656
}
5757

5858
var x: { [x: string]: string }
59+
var xn: {[x: string]: number }
5960
var y: { [x: number]: string }
61+
var yn: { [x: number]: number }
6062
var z: { [x: E]: number }
6163

6264
x = x;
@@ -70,7 +72,11 @@ y = z;
7072
z = x;
7173
z = y;
7274
z = z;
75+
z = yn;
76+
z = xn;
7377

78+
// TODO: Should fail
79+
yn = z;
7480

7581
type foo = string
7682
var s: { [x: foo]: string }

0 commit comments

Comments
 (0)