Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

One way to eliminate all TypeScript annotations in a TypeScript file is to use a tool called ts-transpile-only. Here's how:

  1. Install ts-transpile-only:
npm install -g ts-transpile-only
  1. Create a .tsconfig file with compilerOptions set to:
{
  "compilerOptions": {
    "removeComments": true,
    "noEmitHelpers": true,
    "lib": ["es6"],
    "types": [],
    "module": "commonjs",
    "target": "es5",
    "jsx": "react",
    "strict": false,
    "esModuleInterop": true,
    "noImplicitAny": false,
    "sourceMap": false
  }
}

Note: the removeComments option is set to true to remove comments in addition to annotations, and target and module options are set to es5 and commonjs respectively to ensure compatibility with old browsers and Node.js.

  1. Run ts-transpile-only with the --removeComments flag:
ts-transpile-only your-file.ts --removeComments

This will output the transpiled JavaScript code without any TypeScript annotations.