Skip to content
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

tsconfig.json option removeComments removes comments from both declaration.d.ts and source .js files, it would be convenient to only remove comments from .js files. #45187

Open
5 tasks done
wandyezj opened this issue Jul 26, 2021 · 2 comments
Labels
Awaiting More Feedback This means we'd like to hear from more people who would be helped by this feature Suggestion An idea for TypeScript

Comments

@wandyezj
Copy link

wandyezj commented Jul 26, 2021

Suggestion

The TypeScript tsconfig.json removeComments removes all comments from both declaration and source files. It would be convenient to be able to specify removeCommentsFromDeclaration (.d.ts) and removeCommentsFromModule (.js) independently.

🔍 Search Terms

removeComments

✅ Viability Checklist

My suggestion meets these guidelines:

  • This wouldn't be a breaking change in existing TypeScript/JavaScript code
  • This wouldn't change the runtime behavior of existing JavaScript code
  • This could be implemented without emitting different JS based on the types of the expressions
  • This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, new syntax sugar for JS, etc.)
  • This feature would agree with the rest of TypeScript's Design Goals.

⭐ Suggestion

Source .js files are used directly when importing packages and do not need comments as these can contribute to the size.

It is often undesirable to show off internal comments, especially when developing external libraries.

Declaration .d.ts files are used for IntelliSense and it is usually desired for them to have comments, api-extractor uses generated declarations for documentation extraction.

While there are work arounds, they require running additional commands instead of getting everything in one go.

Provide removeCommentsFromDeclaration (.d.ts) and removeCommentsFromModule (.js) options alongside the existing removeComments OR allow removeComments to be overloaded to have ["declaration", "module"] to specify the specific comments to remove.

📃 Motivating Example

Remove comments from .js to:

  • reduce size of the package when uploaded to NPM and downloaded from NPM
  • reduce size of packages on disk
  • reduce size of imports without post processing
  • hide internal package comments from external developers

💻 Use Cases

The workaround is to have the .d.ts and .js be potentially out of sync by running two separate commands to generate the .d.ts and .js files.

@wandyezj wandyezj changed the title tsconfig.json option removeComments removes comments from both declaration.d.ts and source .js files, it would be convenient if it could be specified to remove comments only from .js files. tsconfig.json option removeComments removes comments from both declaration.d.ts and source .js files, it would be convenient to only remove comments from .js files. Jul 26, 2021
@andrewbranch andrewbranch added Awaiting More Feedback This means we'd like to hear from more people who would be helped by this feature Suggestion An idea for TypeScript labels Jul 26, 2021
@AviVahl
Copy link

AviVahl commented Jul 28, 2021

Related:
#38427
#14619

@wandyezj
Copy link
Author

wandyezj commented Aug 3, 2021

I'm happy to contribute this piece of code, since I find this issue particularly inconvenient. Reading though the related, is there a specific design that the TypeScript team already has in mind?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Awaiting More Feedback This means we'd like to hear from more people who would be helped by this feature Suggestion An idea for TypeScript
Projects
None yet
Development

No branches or pull requests

3 participants