microsoft / microsoft/TypeScript

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.

Open
#45,187 3 comments 19 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Awaiting More Feedback Suggestion
Dominant language
Go
Stars
111k
Forks
14.4k
Avg merge
1d 19h
Merged PRs (30d)
117

Description

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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the tsconfig.json removeComments option and compare declaration (.d.ts) and source (.js) emission. Determine whether separate options or an overloaded value should control comments independently, then verify that existing behavior remains unchanged and both output types can be configured as requested.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, typescript
Domain
compilers
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.