-
Notifications
You must be signed in to change notification settings - Fork 12.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Preserve JSDocs in *.d.ts files when stripping comments #14619
Comments
it makes no sense to remove the comments from declaration files, since they are mainly used during development and won't go into production, I was expecting too that |
Legitimate question - why is anyone using |
unminified code not for the browser, mainly. split code base into composable components that will later become part of something bigger (but while in dev, useful being on the consumer part of it). comments in JS = not useful. Comments in .d.ts, uber useful. Shared code (usually interfaces and mapping objects) that are used in both server and browser, and while it's good to have the comments to be kept in the server side, it's a bad idea to have them shared to the client code (such as comments regarding internal structure, database table names, etc) |
Is this still on the horizon? This is a bit of a pain point with respect to my work-around for #21566 when generating declaration files. Fortunately in my case the declaration file is equivalent to the input source file so i can just replace the generated declaration file with a copied and renamed source file in automation. |
@DanielRosenwasser, I frequently publish byte-size packages using typescript as my only build step. I usually want my code minified, but my comments available in the declarations since they are doc comments. This is a wonderfully simple way for my to publish packages rather than incorporating a bundler with plugins. |
HAPPY ONE YEAR ANNIVERSERY!!!!! Its been exactly 1 YEAR today since this was opened. Are we any closer to having this resolved? This doesn't seem to be a lot of work to fix, but given we've had two duplicates since this was opened, it is something people want. I know I'd like to use it on my OSS projects... |
On a related note: if/when this does get fixed, it would be nice to also adjust the .d.ts output slightly, so that there's a space between doc-blocks and declarations. Currently it's all crammed together. |
@RyanCavanaugh why mark my reply with a thumbs down? I think its quite valid to ask what's going on with a feature that's been 'In Discussion' for over a year. It would have been more helpful to the community to have spent time replying with an actual update, rather than just being rude! |
I'd suggest |
hope can have this, |
@DanielRosenwasser to answer your question: Comments for development (Starting with Comments for API consumers (JSDoc) should live either in the declaration My ideal situation:
Since VSCode looks at the This could use the tsconfig suggestion @championswimmer made. |
I was looking at releasing a typescript library and was really surprised when my comments were either being stripped altogether or completely left in. Having intellisense would be really helpful to end users, but a lot of comments just makes the package size larger. Though, it did help explain why so many of my third party libraries have nice types but no intellisense documentation. Is there anything we can do as a community to move this forward? I see official comments, but no confirmation about how to resolve. Given that the proposed solutions are bigger (maybe) not backwards-compatible changes, maybe getting buy-in from one of the core team is important before starting work? |
At least until something is done with microsoft/TypeScript#14619
QuestionShould JSDoc comments be stripped from public APIs of compiled output While I'd be happy with @championswimmer's suggestion, I don't see that as compatible with existing options. Based on one discussion that I've had with some on the TS team, one high priority is keep consistent non confusing compiler options. Therefore I'm betting that adding a Backwards Compatible SolutionWhat if if (removeComments === false) removeComments = 'none';
if (removeComments === true) removeComments = 'code';
AlternativeAs the |
Until microsoft/TypeScript#14619 is resolved
- move all types from typegoose.ts to types.ts - move many types from prop.ts to types.ts - add tsdoc for some types - typegoose.ts: rename t argument to cl - set "removeComments" rule to false to add tsdoc comments to .d.ts Note: keep "removeComments" as "false" as long as microsoft/TypeScript#14619 isnt fixed
- move all types from typegoose.ts to types.ts - move many types from prop.ts to types.ts - add tsdoc for some types - typegoose.ts: rename t argument to cl - set "removeComments" rule to false to add tsdoc comments to .d.ts Note: keep "removeComments" as "false" as long as microsoft/TypeScript#14619 isnt fixed
I was going to submit a separate issue, but I believe mine is related. Why can't TypeScript give us docstrings? |
Is this going to be fixed |
So this problem became something big? 😪 I thought I could fix it in 5 minutes of googling If you are here searching for an answer to this issue, DONT typescript does not support it! |
This suggestion has been in discussion for over half a decade (specifically: 2,041 days at the time of writing). @RyanCavanaugh do you and your team plan to show an interest in features the community have actively wanted for 2041 days, or will you continue to ignore it for another five years? This feature is simple, highly requested, and is actually a bug report ( |
@willster277 A workaround using project references: https://github.com/webstrand/typescript-remove-comments-not-from-declarations Running |
@webstrand it's shocking that we have to use 3rd party libraries to fix a Microsoft product. Actually, it's exactly what I expect from Microsoft, which is arguably even worse. |
@willster277 Actually that's not 3rd-party. The repo's just an example of how to set the project up. |
@webstrand my bad I'm on mobile, I thought you had sent a fork/project. I have done this before, but it's not ideal. It would be much better if Typescript didn't destroy information. |
I use TypeScript to generate definitions for my JS source files (for use in libraries), and the lack of carryover from JSDoc comments on functions was disappointing. Since it doesn't seem this will be supported any time soon, I built a post-build script that copies over the JSDoc comments (less redundant type info) for functions declare in the If anybody is interested in trying this approach, I've dropped the script in a gist here: https://gist.github.com/coreyward/e70642a41e2181641a817a632a82cd2d |
{
"removeComments": true,
"preserveJSDoc": true
} Hope it can be implemented like this. |
Took some doing since there's no nice way in TS of omitting comments from the resulting JS files but keeping them in the TS files. See microsoft/TypeScript#14619 for the relevant issue discussing this. Fixes MichalLytek#1442
Took some doing since there's no nice way in TS of omitting comments from the resulting JS files but keeping them in the TS files. See microsoft/TypeScript#14619 for the relevant issue discussing this. Fixes MichalLytek#1442
Took some doing since there's no nice way in TS of omitting comments from the resulting JS files but keeping them in the TS files. See microsoft/TypeScript#14619 for the relevant issue discussing this. Fixes MichalLytek#1442
One helpful thing would also be to remove type declarations within the preserved JSDoc comments as they're redundant, and may cause issues sometimes. Additionally, sometimes I use |
A sane workaround:
With "removeComments": false,
"declaration": false, Builds stripped JS, then emits declarations with JSDoc preserved. |
This being wanted and not being implemented for about ten years is just sad. Classic Microsoft! 🎉🎉 |
Could you explain this workaround @michal-kapala ? I have many projects already underway and I really need the d.ts to gain the comments. It seems like this solution requires a deep understanding of how the I have a {
"compilerOptions": {
"emitDeclarationOnly": true,
"declaration": true,
"outDir": "./dist",
"downlevelIteration": true,
"removeComments": false
},
"files": [ ... ]
} And it does NOT produce comments in the generated Edit: I guess I have to specifically use jsdoc style to get it to preserve. |
@unphased It is a simple 2-step build:
Options passed via command line override the ones in |
Thanks. I figured it out. With my existing setup all I had to do was adjust my comments to Jason/javadoc style with |
Suggestion/Feature
When using the switch
removeComments
it will strip out all comments including the ones you may consider useful to the end consumer such as JSDocs. I'd like to strip out any internal comments but preserve any JSDocs comments. It seems that an option to preserve comments in types would be sufficient.Existing functionality
removes all comments including those in *.d.ts files.
Suggested functionality
I would think by default you'd want to include the JSDocs in your type defs, so this would remove all comments from the code, but retain any comments associated with the types ie JSDocs.
If however, there is a need to remove all comments then an additional switch may be required to serve that purpose:
Would produce the same result we have today.
The text was updated successfully, but these errors were encountered: