mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-15 21:36:50 -05:00
fix(37519): forbid trailing comma in a index signature (#37535)
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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.
|
||||
}
|
||||
|
||||
20
tests/baselines/reference/indexSignatureWithTrailingComma.js
Normal file
20
tests/baselines/reference/indexSignatureWithTrailingComma.js
Normal 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;
|
||||
}());
|
||||
@@ -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))
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
11
tests/cases/compiler/indexSignatureWithTrailingComma.ts
Normal file
11
tests/cases/compiler/indexSignatureWithTrailingComma.ts
Normal file
@@ -0,0 +1,11 @@
|
||||
type A = {
|
||||
[key: string,]: string;
|
||||
};
|
||||
|
||||
interface B {
|
||||
[key: string,]: string;
|
||||
}
|
||||
|
||||
class C {
|
||||
[key: string,]: null;
|
||||
}
|
||||
Reference in New Issue
Block a user