diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index cc04bd02d9b3d..2c471b9818eb4 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -26248,14 +26248,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); } } diff --git a/tests/baselines/reference/jsdocIllegalTags.errors.txt b/tests/baselines/reference/jsdocIllegalTags.errors.txt new file mode 100644 index 0000000000000..485d01b12d9c2 --- /dev/null +++ b/tests/baselines/reference/jsdocIllegalTags.errors.txt @@ -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() {} + } + \ No newline at end of file diff --git a/tests/baselines/reference/jsdocIllegalTags.symbols b/tests/baselines/reference/jsdocIllegalTags.symbols new file mode 100644 index 0000000000000..615bdc2facd43 --- /dev/null +++ b/tests/baselines/reference/jsdocIllegalTags.symbols @@ -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() {} +} + diff --git a/tests/baselines/reference/jsdocIllegalTags.types b/tests/baselines/reference/jsdocIllegalTags.types new file mode 100644 index 0000000000000..c40302f11d3e9 --- /dev/null +++ b/tests/baselines/reference/jsdocIllegalTags.types @@ -0,0 +1,14 @@ +=== /a.js === +class C { +>C : C + + /** @template T */ + constructor() { } +} +class D { +>D : D + + /** @return {number} */ + constructor() {} +} + diff --git a/tests/cases/compiler/jsdocIllegalTags.ts b/tests/cases/compiler/jsdocIllegalTags.ts new file mode 100644 index 0000000000000..a59a70dda87f2 --- /dev/null +++ b/tests/cases/compiler/jsdocIllegalTags.ts @@ -0,0 +1,13 @@ +// @allowJs: true +// @checkJs: true +// @noEmit: true +// @Filename: /a.js + +class C { + /** @template T */ + constructor() { } +} +class D { + /** @return {number} */ + constructor() {} +}