fix(37519): forbid trailing comma in a index signature (#37535)

This commit is contained in:
Alexander T
2020-04-02 01:38:10 +03:00
committed by GitHub
parent 95a124f802
commit 697d1042eb
7 changed files with 105 additions and 0 deletions

View File

@@ -36658,6 +36658,7 @@ namespace ts {
return grammarErrorOnNode(node, Diagnostics.An_index_signature_must_have_exactly_one_parameter);
}
}
checkGrammarForDisallowedTrailingComma(node.parameters, Diagnostics.An_index_signature_cannot_have_a_trailing_comma);
if (parameter.dotDotDotToken) {
return grammarErrorOnNode(parameter.dotDotDotToken, Diagnostics.An_index_signature_cannot_have_a_rest_parameter);
}

View File

@@ -83,6 +83,10 @@
"category": "Error",
"code": 1024
},
"An index signature cannot have a trailing comma.": {
"category": "Error",
"code": 1025
},
"Accessibility modifier already seen.": {
"category": "Error",
"code": 1028

View File

@@ -0,0 +1,24 @@
tests/cases/compiler/indexSignatureWithTrailingComma.ts(2,17): error TS1025: An index signature cannot have a trailing comma.
tests/cases/compiler/indexSignatureWithTrailingComma.ts(6,17): error TS1025: An index signature cannot have a trailing comma.
tests/cases/compiler/indexSignatureWithTrailingComma.ts(10,17): error TS1025: An index signature cannot have a trailing comma.
==== tests/cases/compiler/indexSignatureWithTrailingComma.ts (3 errors) ====
type A = {
[key: string,]: string;
~
!!! error TS1025: An index signature cannot have a trailing comma.
};
interface B {
[key: string,]: string;
~
!!! error TS1025: An index signature cannot have a trailing comma.
}
class C {
[key: string,]: null;
~
!!! error TS1025: An index signature cannot have a trailing comma.
}

View File

@@ -0,0 +1,20 @@
//// [indexSignatureWithTrailingComma.ts]
type A = {
[key: string,]: string;
};
interface B {
[key: string,]: string;
}
class C {
[key: string,]: null;
}
//// [indexSignatureWithTrailingComma.js]
var C = /** @class */ (function () {
function C() {
}
return C;
}());

View File

@@ -0,0 +1,23 @@
=== tests/cases/compiler/indexSignatureWithTrailingComma.ts ===
type A = {
>A : Symbol(A, Decl(indexSignatureWithTrailingComma.ts, 0, 0))
[key: string,]: string;
>key : Symbol(key, Decl(indexSignatureWithTrailingComma.ts, 1, 5))
};
interface B {
>B : Symbol(B, Decl(indexSignatureWithTrailingComma.ts, 2, 2))
[key: string,]: string;
>key : Symbol(key, Decl(indexSignatureWithTrailingComma.ts, 5, 5))
}
class C {
>C : Symbol(C, Decl(indexSignatureWithTrailingComma.ts, 6, 1))
[key: string,]: null;
>key : Symbol(key, Decl(indexSignatureWithTrailingComma.ts, 9, 5))
}

View File

@@ -0,0 +1,22 @@
=== tests/cases/compiler/indexSignatureWithTrailingComma.ts ===
type A = {
>A : A
[key: string,]: string;
>key : string
};
interface B {
[key: string,]: string;
>key : string
}
class C {
>C : C
[key: string,]: null;
>key : string
>null : null
}

View File

@@ -0,0 +1,11 @@
type A = {
[key: string,]: string;
};
interface B {
[key: string,]: string;
}
class C {
[key: string,]: null;
}