Skip to content
Tutorials Center
My learning

Topics

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

TypeScript erasableSyntaxOnly option

Reference for erasableSyntaxOnly: reject enums, namespaces and parameter properties so TypeScript files run directly in Node by erasing types, error TS1294.

Most TypeScript syntax is a layer of annotations over JavaScript: delete the types and a valid program remains. A few constructs are different because they generate code: enum, namespace with values, class parameter properties (constructor(private x: number)), and the import x = require() forms. erasableSyntaxOnly makes the compiler report an error for exactly those constructs (TS1294).

This matters because runtimes that run .ts files directly, such as Node's type stripping, work by blanking out the type syntax and doing nothing else. If your code uses only erasable syntax, node main.ts runs it unchanged. The option was added in TypeScript 5.8 and is usually combined with noEmit and verbatimModuleSyntax.

JSON
{ "compilerOptions": { "erasableSyntaxOnly": true } }

Try it

TypeScript Erasable code is stripped to plain JavaScript

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 An enum cannot be erased

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": { "erasableSyntaxOnly": true } }
Construct Allowed? Erasable alternative
enum, const enum No (TS1294) as const object and a union type
namespace / module with values No ES modules or a plain object
Namespaces containing only types Yes none needed
Parameter properties (constructor(public x: number)) No Declare the field and assign it in the constructor
import x = require("m"), export = x No import / export default
Type annotations, interface, type, as, satisfies, generics, declare Yes none needed

Usage notes

  • Node strips types by default from version 23.6 and 22.18 onward; its error code for the unsupported constructs is ERR_UNSUPPORTED_TYPESCRIPT_SYNTAX. Older versions required a flag.
  • Type stripping needs .ts import specifiers in relative imports (import "./a.ts"). Pair the option with allowImportingTsExtensions/rewriteRelativeImportExtensions as your build requires.
  • Decorators are not erasable in the same sense; they remain a separate topic for runtimes without transform support.
  • Existing code using enums can migrate gradually: turn the option on and fix the reported errors one by one.
  • The option checks syntax only. It does not stop you from using type-dependent features such as const enum values imported from other files.
  • It conflicts with nothing else, but it is only useful if the code really runs without a compile step.