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

allow trailing comman in type arguments list #22325

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27614,8 +27614,7 @@ namespace ts {
}

function checkGrammarTypeArguments(node: Node, typeArguments: NodeArray<TypeNode> | undefined): boolean {
return checkGrammarForDisallowedTrailingComma(typeArguments) ||
checkGrammarForAtLeastOneTypeArgument(node, typeArguments);
return checkGrammarForAtLeastOneTypeArgument(node, typeArguments);
}

function checkGrammarForOmittedArgument(args: NodeArray<Expression> | undefined): boolean {
Expand Down
17 changes: 17 additions & 0 deletions tests/baselines/reference/allowTrailingCommasInTypeArguments.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//// [allowTrailingCommasInTypeArguments.ts]
class FooClass<A, B, C,> {
a: A;
b: B;
c: C;
}

var a = new FooClass<number, number, number,>();


//// [allowTrailingCommasInTypeArguments.js]
var FooClass = /** @class */ (function () {
function FooClass() {
}
return FooClass;
}());
var a = new FooClass();
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
=== tests/cases/compiler/allowTrailingCommasInTypeArguments.ts ===
class FooClass<A, B, C,> {
>FooClass : Symbol(FooClass, Decl(allowTrailingCommasInTypeArguments.ts, 0, 0))
>A : Symbol(A, Decl(allowTrailingCommasInTypeArguments.ts, 0, 15))
>B : Symbol(B, Decl(allowTrailingCommasInTypeArguments.ts, 0, 17))
>C : Symbol(C, Decl(allowTrailingCommasInTypeArguments.ts, 0, 20))

a: A;
>a : Symbol(FooClass.a, Decl(allowTrailingCommasInTypeArguments.ts, 0, 26))
>A : Symbol(A, Decl(allowTrailingCommasInTypeArguments.ts, 0, 15))

b: B;
>b : Symbol(FooClass.b, Decl(allowTrailingCommasInTypeArguments.ts, 1, 6))
>B : Symbol(B, Decl(allowTrailingCommasInTypeArguments.ts, 0, 17))

c: C;
>c : Symbol(FooClass.c, Decl(allowTrailingCommasInTypeArguments.ts, 2, 6))
>C : Symbol(C, Decl(allowTrailingCommasInTypeArguments.ts, 0, 20))
}

var a = new FooClass<number, number, number,>();
>a : Symbol(a, Decl(allowTrailingCommasInTypeArguments.ts, 6, 3))
>FooClass : Symbol(FooClass, Decl(allowTrailingCommasInTypeArguments.ts, 0, 0))

25 changes: 25 additions & 0 deletions tests/baselines/reference/allowTrailingCommasInTypeArguments.types
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
=== tests/cases/compiler/allowTrailingCommasInTypeArguments.ts ===
class FooClass<A, B, C,> {
>FooClass : FooClass<A, B, C>
>A : A
>B : B
>C : C

a: A;
>a : A
>A : A

b: B;
>b : B
>B : B

c: C;
>c : C
>C : C
}

var a = new FooClass<number, number, number,>();
>a : FooClass<number, number, number>
>new FooClass<number, number, number,>() : FooClass<number, number, number>
>FooClass : typeof FooClass

5 changes: 1 addition & 4 deletions tests/baselines/reference/syntaxErrors.errors.txt
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
tests/cases/conformance/jsdoc/badTypeArguments.js(1,15): error TS1099: Type argument list cannot be empty.
tests/cases/conformance/jsdoc/badTypeArguments.js(2,22): error TS1009: Trailing comma not allowed.


==== tests/cases/conformance/jsdoc/dummyType.d.ts (0 errors) ====
declare class C<T> { t: T }

==== tests/cases/conformance/jsdoc/badTypeArguments.js (2 errors) ====
==== tests/cases/conformance/jsdoc/badTypeArguments.js (1 errors) ====
/** @param {C.<>} x */
~~
!!! error TS1099: Type argument list cannot be empty.
/** @param {C.<number,>} y */
~
!!! error TS1009: Trailing comma not allowed.
// @ts-ignore
/** @param {C.<number,>} skipped */
function f(x, y, skipped) {
Expand Down
7 changes: 7 additions & 0 deletions tests/cases/compiler/allowTrailingCommasInTypeArguments.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class FooClass<A, B, C,> {
a: A;
b: B;
c: C;
}

var a = new FooClass<number, number, number,>();