Skip to content
Tutorials Center
My learning

Topics

TypeScript Reference ยท tsconfig: Language, Modules and Emit Options

TypeScript removeComments option

Reference for removeComments: drop comments from compiled JavaScript to shrink output, what survives (/*! and triple-slash lines) and what it ignores.

removeComments tells the compiler to leave comments out of the files it emits. Source files keep their comments; only the generated .js (and .d.ts) are affected. The result is a slightly smaller file and no leaked internal remarks.

The effect is small compared with minification, so it rarely changes anything for users. It is useful when you ship unbundled output and do not want implementation notes, or license-irrelevant chatter, in the published package.

JSON
{ "compilerOptions": { "removeComments": true } }

Try it

Comments are invisible to running code, except in one place: a function's toString() returns its source text, and so reveals which comments survived emit. The runner here keeps comments, so you can see them.

TypeScript Comments inside a function body

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with node:readline or readFileSync(0)), it gets the next line from this box.

TypeScript Types disappear, comments may too

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with node:readline or readFileSync(0)), it gets the next line from this box.

Syntax

JSON
{ "compilerOptions": { "removeComments": true } }
Name Description
removeComments true removes comments from emitted files. Default false.

Usage notes

  • Comments starting with /*! are kept, which is the usual convention for license banners.
  • Triple-slash directives such as /// <reference ... /> are handled separately and are not treated as ordinary comments.
  • With declaration, JSDoc comments in .d.ts files are removed too, which hurts editor documentation for library users. Many libraries leave this option off for that reason.
  • Bundlers and minifiers strip comments on their own, so enabling it in tsc is redundant when you bundle.
  • Types are erased no matter what; this option only concerns comments.
  • Directives such as // @ts-ignore live only in the source; they do not need to survive.