Skip to content

Commit 6225c77

Browse files
committed
Add test for string alias.
1 parent 0202efb commit 6225c77

File tree

2 files changed

+21
-17
lines changed

2 files changed

+21
-17
lines changed

src/compiler/checker.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12114,7 +12114,7 @@ module ts {
1211412114

1211512115
if (parameter.type.kind === SyntaxKind.TypeReference) {
1211612116
var type = getTypeFromTypeReference(<TypeReferenceNode>(parameter.type));
12117-
if (type.flags & TypeFlags.NumberLike) {
12117+
if ((type.flags & TypeFlags.NumberLike) || (type.flags & TypeFlags.String)) {
1211812118
return type;
1211912119
}
1212012120
}

tests/cases/compiler/indexSignatureTypeCheck.ts

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

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

14-
type Val2 = Val;
15-
type Val3 = number;
14+
type Values2 = Values;
15+
type Values3 = number;
1616

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

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

29-
var pe: IEnum = null;
28+
var pe: Values = null;
3029

3130
pe[1] = null
3231
pe[3] = null
33-
pe[Val.b] = 5
32+
pe[Values.b] = 5
3433

3534
pe[true] = null
3635

@@ -47,13 +46,13 @@ enum E {
4746

4847

4948
interface DuplicateAccess {
50-
[index: Val]: Val;
51-
[index: Val2]: Val2;
49+
[index: Values]: Values;
50+
[index: Values2]: Values2;
5251
}
5352

5453
interface DuplicateAccess2 {
55-
[index: number]: Val;
56-
[index: Val3]: Val3;
54+
[index: number]: Values;
55+
[index: Values3]: Values3;
5756
}
5857

5958
var x: { [x: string]: string }
@@ -72,3 +71,8 @@ z = x;
7271
z = y;
7372
z = z;
7473

74+
75+
type foo = string
76+
var s: { [x: foo]: string }
77+
x = s
78+
s = x

0 commit comments

Comments
 (0)