Repository navigation
Report error for duplicate @type declaration in @typedef #17442
Description
Activity
- addedDomain: JSDocRelates to JSDoc parsing and type generationRelates to JSDoc parsing and type generation
on Aug 23, 2017 - addedGood First IssueWell scoped, documented and has the green lightWell scoped, documented and has the green light
on Apr 12, 2018 Hi Mohamed Hegazy (@mhegazy) can I try that one?
Noam Yogev (@noamyogev84) Go for it!
Reacted by Noam YogevThanks Nathan Shively-Sanders (@sandersn). can you please share some code pointers?
You'll want to start in
parseTypedefTagin parser.ts. There is a section of code that checks for the child@typeinside@typedef:while (child = tryParse(() => parseChildPropertyTag(indent))) { // ... if (child.kind === SyntaxKind.JSDocTypeTag) { if (childTypeTag) { break; } else { childTypeTag = child; } } // ... }
As you can see, in case of duplicate
@typetags, the code just breaks out of the loop with no error. Add a call toparseErrorAtCurrentTokenbefore breaking out of the loop.DiagnosticMessages.Unexpected_tokenis probably good enough for the message, but you can add a new one in diagnosticMessages.json if you want. Maybe "Unexpected tag '{0}'." or "Duplicate tag '{0}'."For adding tests, follow the directions in CONTRIBUTING, except that you should add your test in
ts/tests/cases/conformance/jsdoc, and you will need to explicitly allow JS at the top:// @allowJS: true // @checkJS: true // @noEmit: true // @Filename: bug17442.js // ... actual test goes here ...
Daniel Rosenwasser (@DanielRosenwasser) any opinions on what the error message should be?
Reacted by Noam YogevGreat I'm on it.
Hi Nathan Shively-Sanders (@sandersn),
Following your directions does not produce the wanted result, or maybe i'm missing something. (No error message is outputted by the compiler)
I'm debugging tsc.js and it seems likeparseErrorAtCurrentTokendoes not affect the rest of the method."Planting" an arbitrary syntax error in the above example does produce error, but I still can't figure out where it's being handled. Do you have any idea what's missing?
Nathan Shively-Sanders (@sandersn), Daniel Rosenwasser (@DanielRosenwasser)
Pinging you to get your thoughts on this... .- addedDomain: JavaScriptThe issue relates to JavaScript specificallyThe issue relates to JavaScript specificallyand removed
on Nov 29, 2018 Can I try this one?
DanielRosenwasser commented
on Jan 18, 2019 MemberMore actionsA JSDoc '@typedef' comment may not contain multiple '@type' tags.Bonus points on providing a related span on the first tag if it's not too hard:
The tag was first specified here.DanielRosenwasser commented
on Jan 18, 2019 MemberMore actionsNisha Kaushik (@nisha-kaushik) go for it.
Not sure if Noam Yogev (@noamyogev84) is still looking at this but the issue they were running into might've just been running tests in a
.tsfile or an unchecked.jsfile.Nisha Kaushik (@nisha-kaushik) go ahead.
- locked as resolved and limited conversation to collaborators
on Oct 21, 2025
TypeScript Version: master
Code
Expected behavior:
Error.
Actual behavior:
No error.