Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from Apr 24, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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]
}