mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-12-12 02:28:28 -06:00
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:
parent
334b8590e9
commit
dcb763f624
@ -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;
|
||||
}
|
||||
|
||||
@ -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.
|
||||
|
||||
@ -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))
|
||||
|
||||
@ -0,0 +1,5 @@
|
||||
=== tests/cases/compiler/a.js ===
|
||||
const Bar = class<T> {};
|
||||
>Bar : typeof Bar
|
||||
>class<T> {} : typeof Bar
|
||||
|
||||
@ -0,0 +1,4 @@
|
||||
// @allowJs: true
|
||||
// @noEmit: true
|
||||
// @filename: a.js
|
||||
const Bar = class<T> {};
|
||||
Loading…
x
Reference in New Issue
Block a user