TypeScript --erasableSyntaxOnly 플래그, 왜 생겼고 언제 쓰나

Published: (January 9, 2026 at 08:04 PM EST)
3 min read
Source: Dev.to

Source: Dev.to

What is --erasableSyntaxOnly?

--erasableSyntaxOnly is a new compiler flag introduced in TypeScript 5.8.
When enabled in tsconfig.json, the compiler reports errors for any TypeScript‑only syntax that cannot be simply stripped away without affecting the generated JavaScript runtime.

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

Prohibited Syntax

The flag blocks the following constructs because they require runtime code generation:

ConstructReason
enum declarationsGenerates a JavaScript object
Namespaces that contain runtime codeEmits IIFE wrapper
Parameter properties (constructor(public x: number))Emits property initialization
import = alias syntaxEmits CommonJS‑style import
Old‑style type assertions (value)Needs special emit handling

Erasable vs. Non‑erasable Syntax

Erasable

Erasable syntax can be removed entirely; only its type information is needed.

// ✅ Erasable – type can be stripped
function greet(name: string): string {
  return `Hello, ${name}`;
}

// After erasing types
function greet(name) {
  return `Hello, ${name}`;
}

Non‑erasable

Non‑erasable syntax must stay because it produces observable JavaScript.

// ❌ Non‑erasable – runtime behavior required
enum Status {
  Active,
  Inactive
}
console.log(Status.Active); // 0

Compiled output for the enum:

var Status;
(function (Status) {
    Status[Status["Active"] = 0] = "Active";
    Status[Status["Inactive"] = 1] = "Inactive";
})(Status || (Status = {}));

Removing the enum would cause a runtime error, so it is non‑erasable.

Why This Flag Exists?

Two related developments drive the need for --erasableSyntaxOnly:

  1. Node.js experimental “strip‑types” mode (available from Node 23.6) lets you run a .ts file directly:

    node --experimental-strip-types app.ts

    This mode only strips type annotations; it does not support constructs that need JavaScript emission (e.g., enums, namespaces).

  2. TC39 “Types as Comments” proposal (Stage 1).
    The proposal aims to let browsers ignore TypeScript‑style type annotations as if they were comments, enabling direct execution of TypeScript code without a build step. For this to work, only erasable syntax may be used; any construct that produces runtime artifacts is out of scope.

    “Enums, namespaces, and parameter properties would be out of scope for this proposal since they have observable runtime behavior.” — Daniel Rosenwasser, 2022

Relationship to Enums

The TypeScript team has not deprecated enum. A 2020 GitHub issue titled “Deprecate const enum” was declined, indicating a commitment to backward compatibility.

The official handbook merely suggests modern alternatives:

“In modern TypeScript, you may not need an enum when an object with as const could suffice… The biggest argument in favour of this format over TypeScript’s enum is that it keeps your codebase aligned with the state of JavaScript.”

So the guidance is not “stop using enums,” but consider alternatives that align with JavaScript’s direction.

Below are idiomatic replacements for the prohibited constructs.

Replace enum

// Before
enum Status {
  Active = 'active',
  Inactive = 'inactive'
}

// After
export const Status = {
  Active: 'active',
  Inactive: 'inactive'
} as const;

export type Status = typeof Status[keyof typeof Status];

Replace namespace

// Before
namespace Utils {
  export function format(s: string) { /* ... */ }
}

// After (utils.ts)
export function format(s: string) { /* ... */ }

Replace parameter properties

// Before
class User {
  constructor(public name: string) {}
}

// After
class User {
  name: string;
  constructor(name: string) {
    this.name = name;
  }
}

FAQ

QuestionAnswer
Are enums deprecated?No.
Should new code avoid these constructs?Consider alternatives; it’s recommended for future‑proofing.
Is there a plan to remove them?No removal plan; they remain for backward compatibility.

References

  • TypeScript 5.8 Release Notes – details the new flag.
  • TC39 Proposal – “Types as Comments”
  • Node.js – --experimental-strip-types – documentation for running TypeScript files directly.
  • TypeScript Design Goals – “Align with current and future ECMAScript proposals.”
Back to Blog

Related posts

Read more »

Developer? Or Just a Toolor?

! https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%...