Skip to content
Merged
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
11 changes: 7 additions & 4 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26159,14 +26159,17 @@ namespace ts {
}

function checkGrammarConstructorTypeParameters(node: ConstructorDeclaration) {
if (node.typeParameters) {
return grammarErrorAtPos(node, node.typeParameters.pos, node.typeParameters.end - node.typeParameters.pos, Diagnostics.Type_parameters_cannot_appear_on_a_constructor_declaration);
const typeParameters = getEffectiveTypeParameterDeclarations(node);
if (typeParameters) {
const { pos, end } = isNodeArray(typeParameters) ? typeParameters : first(typeParameters);
return grammarErrorAtPos(node, pos, end - pos, Diagnostics.Type_parameters_cannot_appear_on_a_constructor_declaration);
}
}

function checkGrammarConstructorTypeAnnotation(node: ConstructorDeclaration) {
if (node.type) {
return grammarErrorOnNode(node.type, Diagnostics.Type_annotation_cannot_appear_on_a_constructor_declaration);
const type = getEffectiveReturnTypeNode(node);
if (type) {
return grammarErrorOnNode(type, Diagnostics.Type_annotation_cannot_appear_on_a_constructor_declaration);
}
}

Expand Down
18 changes: 18 additions & 0 deletions tests/baselines/reference/jsdocIllegalTags.errors.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/a.js(2,19): error TS1092: Type parameters cannot appear on a constructor declaration.
/a.js(6,18): error TS1093: Type annotation cannot appear on a constructor declaration.


==== /a.js (2 errors) ====
class C {
/** @template T */
~
!!! error TS1092: Type parameters cannot appear on a constructor declaration.
constructor() { }
}
class D {
/** @return {number} */
~~~~~~
!!! error TS1093: Type annotation cannot appear on a constructor declaration.
constructor() {}
}

14 changes: 14 additions & 0 deletions tests/baselines/reference/jsdocIllegalTags.symbols
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
=== /a.js ===
class C {
>C : Symbol(C, Decl(a.js, 0, 0))

/** @template T */
constructor() { }
}
class D {
>D : Symbol(D, Decl(a.js, 3, 1))

/** @return {number} */
constructor() {}
}

14 changes: 14 additions & 0 deletions tests/baselines/reference/jsdocIllegalTags.types
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
=== /a.js ===
class C {
>C : C

/** @template T */
constructor() { }
}
class D {
>D : D

/** @return {number} */
constructor() {}
}

13 changes: 13 additions & 0 deletions tests/cases/compiler/jsdocIllegalTags.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// @allowJs: true
// @checkJs: true
// @noEmit: true
// @Filename: /a.js

class C {
/** @template T */
constructor() { }
}
class D {
/** @return {number} */
constructor() {}
}