Skip to content

Commit

Permalink
Fix crash getting error for type alias index signature without a type
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewbranch committed Apr 24, 2019
1 parent 6608349 commit 9564368
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/compiler/checker.ts
Expand Up @@ -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)) {
Expand Down
13 changes: 11 additions & 2 deletions tests/baselines/reference/indexerConstraints2.errors.txt
Expand Up @@ -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; }

Expand Down Expand Up @@ -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.
}

8 changes: 7 additions & 1 deletion tests/baselines/reference/indexerConstraints2.js
Expand Up @@ -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 () {
Expand Down
12 changes: 12 additions & 0 deletions tests/baselines/reference/indexerConstraints2.symbols
Expand Up @@ -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))
}

9 changes: 9 additions & 0 deletions tests/baselines/reference/indexerConstraints2.types
Expand Up @@ -118,3 +118,12 @@ interface S {
[u: "foo" | "bar"]: A;
>u : IndexableUnion
}

type Key = string;
>Key : string

interface T {
[key: Key]
>key : string
}

7 changes: 6 additions & 1 deletion tests/cases/compiler/indexerConstraints2.ts
Expand Up @@ -72,4 +72,9 @@ interface R {

interface S {
[u: "foo" | "bar"]: A;
}
}

type Key = string;
interface T {
[key: Key]
}

0 comments on commit 9564368

Please sign in to comment.