Skip to content

Commit 1b7b3eb

Browse files
authored
report error for duplicate @type declaration (microsoft#38340)
1 parent 738b6b5 commit 1b7b3eb

6 files changed

+52
-0
lines changed

src/compiler/diagnosticMessages.json

+8
Original file line numberDiff line numberDiff line change
@@ -4911,6 +4911,14 @@
49114911
"category": "Error",
49124912
"code": 8032
49134913
},
4914+
"A JSDoc '@typedef' comment may not contain multiple '@type' tags.": {
4915+
"category": "Error",
4916+
"code": 8033
4917+
},
4918+
"The tag was first specified here.": {
4919+
"category": "Error",
4920+
"code": 8034
4921+
},
49144922
"Only identifiers/qualified-names with optional type arguments are currently supported in a class 'extends' clause.": {
49154923
"category": "Error",
49164924
"code": 9002

src/compiler/parser.ts

+8
Original file line numberDiff line numberDiff line change
@@ -7483,6 +7483,14 @@ namespace ts {
74837483
}
74847484
if (child.kind === SyntaxKind.JSDocTypeTag) {
74857485
if (childTypeTag) {
7486+
parseErrorAtCurrentToken(Diagnostics.A_JSDoc_typedef_comment_may_not_contain_multiple_type_tags);
7487+
const lastError = lastOrUndefined(parseDiagnostics);
7488+
if (lastError) {
7489+
addRelatedInfo(
7490+
lastError,
7491+
createDiagnosticForNode(sourceFile, Diagnostics.The_tag_was_first_specified_here)
7492+
);
7493+
}
74867494
break;
74877495
}
74887496
else {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
tests/cases/conformance/jsdoc/typedefDuplicateTypeDeclaration.js(4,16): error TS8033: A JSDoc '@typedef' comment may not contain multiple '@type' tags.
2+
3+
4+
==== tests/cases/conformance/jsdoc/typedefDuplicateTypeDeclaration.js (1 errors) ====
5+
/**
6+
* @typedef Name
7+
* @type {string}
8+
* @type {Oops}
9+
10+
*/
11+
12+
!!! error TS8033: A JSDoc '@typedef' comment may not contain multiple '@type' tags.
13+
!!! related TS8034 tests/cases/conformance/jsdoc/typedefDuplicateTypeDeclaration.js:1:1: The tag was first specified here.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
=== tests/cases/conformance/jsdoc/typedefDuplicateTypeDeclaration.js ===
2+
/**
3+
No type information for this code. * @typedef Name
4+
No type information for this code. * @type {string}
5+
No type information for this code. * @type {Oops}
6+
No type information for this code. */
7+
No type information for this code.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
=== tests/cases/conformance/jsdoc/typedefDuplicateTypeDeclaration.js ===
2+
/**
3+
No type information for this code. * @typedef Name
4+
No type information for this code. * @type {string}
5+
No type information for this code. * @type {Oops}
6+
No type information for this code. */
7+
No type information for this code.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// @allowJS: true
2+
// @checkJS: true
3+
// @noEmit: true
4+
// @Filename: typedefDuplicateTypeDeclaration.js
5+
/**
6+
* @typedef Name
7+
* @type {string}
8+
* @type {Oops}
9+
*/

0 commit comments

Comments
 (0)