Skip to content

Commit 9564368

Browse files
committed
Fix crash getting error for type alias index signature without a type
1 parent 6608349 commit 9564368

File tree

6 files changed

+46
-5
lines changed

6 files changed

+46
-5
lines changed

src/compiler/checker.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31005,7 +31005,7 @@ namespace ts {
3100531005
Diagnostics.An_index_signature_parameter_type_cannot_be_a_type_alias_Consider_writing_0_Colon_1_Colon_2_instead,
3100631006
getTextOfNode(parameter.name),
3100731007
typeToString(type),
31008-
typeToString(getTypeFromTypeNode(node.type!)));
31008+
typeToString(node.type ? getTypeFromTypeNode(node.type) : anyType));
3100931009
}
3101031010

3101131011
if (type.flags & TypeFlags.Union && allTypesAssignableToKind(type, TypeFlags.StringLiteral, /*strict*/ true)) {

tests/baselines/reference/indexerConstraints2.errors.txt

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,10 @@ tests/cases/compiler/indexerConstraints2.ts(58,6): error TS1023: An index signat
99
tests/cases/compiler/indexerConstraints2.ts(64,6): error TS1023: An index signature parameter type must be 'string' or 'number'.
1010
tests/cases/compiler/indexerConstraints2.ts(70,6): error TS1023: An index signature parameter type must be 'string' or 'number'.
1111
tests/cases/compiler/indexerConstraints2.ts(74,6): error TS1337: An index signature parameter type cannot be a union type. Consider using a mapped object type instead.
12+
tests/cases/compiler/indexerConstraints2.ts(79,6): error TS1336: An index signature parameter type cannot be a type alias. Consider writing '[key: string]: any' instead.
1213

1314

14-
==== tests/cases/compiler/indexerConstraints2.ts (11 errors) ====
15+
==== tests/cases/compiler/indexerConstraints2.ts (12 errors) ====
1516
class A { a: number; }
1617
class B extends A { b: number; }
1718

@@ -108,4 +109,12 @@ tests/cases/compiler/indexerConstraints2.ts(74,6): error TS1337: An index signat
108109
[u: "foo" | "bar"]: A;
109110
~
110111
!!! error TS1337: An index signature parameter type cannot be a union type. Consider using a mapped object type instead.
111-
}
112+
}
113+
114+
type Key = string;
115+
interface T {
116+
[key: Key]
117+
~~~
118+
!!! error TS1336: An index signature parameter type cannot be a type alias. Consider writing '[key: string]: any' instead.
119+
}
120+

tests/baselines/reference/indexerConstraints2.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,13 @@ interface R {
7373

7474
interface S {
7575
[u: "foo" | "bar"]: A;
76-
}
76+
}
77+
78+
type Key = string;
79+
interface T {
80+
[key: Key]
81+
}
82+
7783

7884
//// [indexerConstraints2.js]
7985
var __extends = (this && this.__extends) || (function () {

tests/baselines/reference/indexerConstraints2.symbols

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,3 +155,15 @@ interface S {
155155
>u : Symbol(u, Decl(indexerConstraints2.ts, 73, 5))
156156
>A : Symbol(A, Decl(indexerConstraints2.ts, 0, 0))
157157
}
158+
159+
type Key = string;
160+
>Key : Symbol(Key, Decl(indexerConstraints2.ts, 74, 1))
161+
162+
interface T {
163+
>T : Symbol(T, Decl(indexerConstraints2.ts, 76, 18))
164+
165+
[key: Key]
166+
>key : Symbol(key, Decl(indexerConstraints2.ts, 78, 5))
167+
>Key : Symbol(Key, Decl(indexerConstraints2.ts, 74, 1))
168+
}
169+

tests/baselines/reference/indexerConstraints2.types

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,3 +118,12 @@ interface S {
118118
[u: "foo" | "bar"]: A;
119119
>u : IndexableUnion
120120
}
121+
122+
type Key = string;
123+
>Key : string
124+
125+
interface T {
126+
[key: Key]
127+
>key : string
128+
}
129+

tests/cases/compiler/indexerConstraints2.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,4 +72,9 @@ interface R {
7272

7373
interface S {
7474
[u: "foo" | "bar"]: A;
75-
}
75+
}
76+
77+
type Key = string;
78+
interface T {
79+
[key: Key]
80+
}

0 commit comments

Comments
 (0)