microsoft / TypeScript Public
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? |
|
HAPPY TWO YEAR ANNIVERSARY. @RyanCavanaugh (or anyone else at Microsoft): are you going to respond or just Looking at recent releases I'm getting tempted to look at Kotlin for JS now. Building and using libraries in with Typescript is still way off from the simplicity and consistency of Java/Maven ecosystem. But until then... can we please have this simple feature to retain JSDoc... PLEASE! |
|
hope one day something like this can be merge |
|
Official TypeScript documentation describes the implementation of JSDoc without mentioning this behavior. I think the implicit behavior should be something such as the solutions described above, but the documentation should explicitly describe the behavior. |
|
I'm sure a pull request (with test-coverage and documentation) wouldn't be rejected by the team - this is one of those "duh, obvious" features no one can really object to. But to those of you who think this is a slam dunk and why doesn't it "just" get done: I gave it a shot, and about an hour later, all I've managed to do is run the test-suite, ha ha. The feature itself is probably something like changing the type of Iterating on a codebase of this size and complexity is never quick or easy - there are only so many developers working on this, and I'm sure they have priorities, and yeah, sometimes apparently simple things take more than two years. If you think it's so easy, why don't you do it and submit a PR |
|
Currently, all comments are removed from d.ts when |
|
@Zzzen yes, you are |
|
|
|
in a declaration file? |
|
So do you have any idea why |
|
@Zzzen, because " JSDoc must begin with " From the JSDoc getting started guide:
|
|
Why not just unify the behavior of |
|
There is a way to keep the comments in declaration files only and stripping them from the js files. But it's a little inefficient. Basically, you'll need two tsconfig files.
{
"extends": "./tsconfig.json",
"compilerOptions": {
"declaration": false,
"removeComments": true
},
}Now, while in development run the base tsconfig file, which will preserve the comments in .d.ts and .js files. But during production, run the base tsconfig file first, then the nocomments one. An example npm scripts could be:- "scripts": {
"build": "tsc",
"build:nocomments": "tsc -p ./tsconfig.nocomments.json",
"prod": "npm run build && npm run build:nocomments"
},Running All thanks to this original post in dev.to. |
|
End 2021 and nothing on this... still embarrassing. |
|
hope this feature |
|
jsdoc |
|
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! |


Suggestion/Feature
When using the switch
removeCommentsit 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: