Fix crash getting error for type alias index signature without a type

This commit is contained in:
Andrew Branch 2019-04-24 10:35:23 -07:00
parent 6608349ea2
commit 956436853e
No known key found for this signature in database
GPG Key ID: 22CCA4B120C427D2
6 changed files with 46 additions and 5 deletions

View File

@ -31005,7 +31005,7 @@ namespace ts {
Diagnostics.An_index_signature_parameter_type_cannot_be_a_type_alias_Consider_writing_0_Colon_1_Colon_2_instead,
getTextOfNode(parameter.name),
typeToString(type),
typeToString(getTypeFromTypeNode(node.type!)));
typeToString(node.type ? getTypeFromTypeNode(node.type) : anyType));
}
if (type.flags & TypeFlags.Union && allTypesAssignableToKind(type, TypeFlags.StringLiteral, /*strict*/ true)) {

View File

@ -9,9 +9,10 @@ tests/cases/compiler/indexerConstraints2.ts(58,6): error TS1023: An index signat
tests/cases/compiler/indexerConstraints2.ts(64,6): error TS1023: An index signature parameter type must be 'string' or 'number'.
tests/cases/compiler/indexerConstraints2.ts(70,6): error TS1023: An index signature parameter type must be 'string' or 'number'.
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.
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.
==== tests/cases/compiler/indexerConstraints2.ts (11 errors) ====
==== tests/cases/compiler/indexerConstraints2.ts (12 errors) ====
class A { a: number; }
class B extends A { b: number; }
@ -108,4 +109,12 @@ tests/cases/compiler/indexerConstraints2.ts(74,6): error TS1337: An index signat
[u: "foo" | "bar"]: A;
~
!!! error TS1337: An index signature parameter type cannot be a union type. Consider using a mapped object type instead.
}
}
type Key = string;
interface T {
[key: Key]
~~~
!!! error TS1336: An index signature parameter type cannot be a type alias. Consider writing '[key: string]: any' instead.
}

View File

@ -73,7 +73,13 @@ interface R {
interface S {
[u: "foo" | "bar"]: A;
}
}
type Key = string;
interface T {
[key: Key]
}
//// [indexerConstraints2.js]
var __extends = (this && this.__extends) || (function () {

View File

@ -155,3 +155,15 @@ interface S {
>u : Symbol(u, Decl(indexerConstraints2.ts, 73, 5))
>A : Symbol(A, Decl(indexerConstraints2.ts, 0, 0))
}
type Key = string;
>Key : Symbol(Key, Decl(indexerConstraints2.ts, 74, 1))
interface T {
>T : Symbol(T, Decl(indexerConstraints2.ts, 76, 18))
[key: Key]
>key : Symbol(key, Decl(indexerConstraints2.ts, 78, 5))
>Key : Symbol(Key, Decl(indexerConstraints2.ts, 74, 1))
}

View File

@ -118,3 +118,12 @@ interface S {
[u: "foo" | "bar"]: A;
>u : IndexableUnion
}
type Key = string;
>Key : string
interface T {
[key: Key]
>key : string
}

View File

@ -72,4 +72,9 @@ interface R {
interface S {
[u: "foo" | "bar"]: A;
}
}
type Key = string;
interface T {
[key: Key]
}