Report error when using generic class in js file (#31723)

* Report error when using generic class in js file

* Replace "ClassDeclaration | ClassExpression" to ClassLikeDeclaration

Co-Authored-By: Klaus Meinhardt <klaus.meinhardt1@gmail.com>

* add noEmit:true
This commit is contained in:
Tan Li Hau 2019-08-16 06:49:50 +08:00 committed by Ryan Cavanaugh
parent 334b8590e9
commit dcb763f624
5 changed files with 24 additions and 1 deletions

View File

@ -1833,6 +1833,7 @@ namespace ts {
switch (parent.kind) {
case SyntaxKind.ClassDeclaration:
case SyntaxKind.ClassExpression:
case SyntaxKind.MethodDeclaration:
case SyntaxKind.MethodSignature:
case SyntaxKind.Constructor:
@ -1842,7 +1843,7 @@ namespace ts {
case SyntaxKind.FunctionDeclaration:
case SyntaxKind.ArrowFunction:
// Check type parameters
if (nodes === (<ClassDeclaration | FunctionLikeDeclaration>parent).typeParameters) {
if (nodes === (<ClassLikeDeclaration | FunctionLikeDeclaration>parent).typeParameters) {
diagnostics.push(createDiagnosticForNodeArray(nodes, Diagnostics.type_parameter_declarations_can_only_be_used_in_a_ts_file));
return;
}

View File

@ -0,0 +1,8 @@
tests/cases/compiler/a.js(1,19): error TS8004: 'type parameter declarations' can only be used in a .ts file.
==== tests/cases/compiler/a.js (1 errors) ====
const Bar = class<T> {};
~
!!! error TS8004: 'type parameter declarations' can only be used in a .ts file.

View File

@ -0,0 +1,5 @@
=== tests/cases/compiler/a.js ===
const Bar = class<T> {};
>Bar : Symbol(Bar, Decl(a.js, 0, 5))
>T : Symbol(T, Decl(a.js, 0, 18))

View File

@ -0,0 +1,5 @@
=== tests/cases/compiler/a.js ===
const Bar = class<T> {};
>Bar : typeof Bar
>class<T> {} : typeof Bar

View File

@ -0,0 +1,4 @@
// @allowJs: true
// @noEmit: true
// @filename: a.js
const Bar = class<T> {};