Skip to content
Tutorials Center
My learning

Topics

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

TypeScript importHelpers and noEmitHelpers options

Reference for importHelpers and noEmitHelpers: how tsc shares helper functions like __awaiter through tslib, and why modern targets rarely need them.

When you compile modern syntax for an older target, the compiler sometimes needs small runtime functions to imitate it: __awaiter for async/await, __extends for classes, __spreadArray for spread, and more. By default it writes a copy of each needed helper at the top of every file that uses it, which duplicates code across a project.

importHelpers makes the compiler import the helpers from the tslib package instead, so each exists once. noEmitHelpers does the opposite: it writes no helpers and no imports, and you must supply them yourself. With a modern target such as ES2022 or newer, most helpers are not needed at all.

JSON
{ "compilerOptions": { "importHelpers": true } }

Try it

A helper is just an ordinary function. This is what a spread helper does, written by hand, next to the native operator that makes it unnecessary on modern targets.

TypeScript A helper versus native syntax

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 Syntax that needs no helper on ES2024

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.

The class, async function and object rest above compile to themselves for this ES2024 target; none of them would produce a helper.

Syntax

JSON
{
  "compilerOptions": {
    "target": "es2015",
    "importHelpers": true
  }
}
Terminal
npm install tslib
Name Description
importHelpers Import helpers from tslib instead of inlining them. Needs tslib installed as a dependency.
noEmitHelpers Do not emit helpers or import them. Your own definitions (global functions with the right names) must exist at runtime.

Usage notes

  • Missing tslib gives an error like TS2354 ("This syntax requires an imported helper but module 'tslib' cannot be found").
  • Install tslib as a regular dependency of a published library, not only as a dev dependency.
  • With a recent target, check the output: if nothing needs a helper, the option changes nothing.
  • noEmitHelpers is for special runtimes; it can silently break code if a helper is missing.
  • Bundlers typically transpile with their own helpers, making these options unnecessary there.
  • importHelpers also applies to decorator helpers when experimentalDecorators is on.