# erasableSyntaxOnly

> The `erasableSyntaxOnly` TypeScript compiler option reports errors for syntax that has runtime behavior.

## What does erasableSyntaxOnly do in TypeScript?

The compiler option that disallows TS-specific constructs with runtime semantics, such as `enum`, namespaces with code, parameter properties and `import =`. Ensures the code can be run with type stripping tools.

- Topic: Basics
- Type: concept

## Example

Wrong:

```ts
class User {
  constructor(private name: string) {}
}

enum Status { Active, Banned }
```

Right:

```ts
class User {
  private name: string;
  constructor(name: string) {
    this.name = name;
  }
}

type Status = 'active' | 'banned';
```

Parameter properties and `enum` emit runtime code; explicit fields and a literal union erase cleanly.

## Common mistakes

- Turning on Node type stripping and crashing on an `enum` that only a full compiler can handle.

## Key points

- Code uses union types or `as const` objects instead of `enum`.
- Classes declare fields explicitly instead of using constructor parameter properties.
- Namespaces with runtime code are replaced by modules.

## Interview questions

### Does erasableSyntaxOnly allow namespaces?

Only namespaces that contain types alone, which emit no code. A namespace with values is reported as an error.

### Should I turn on erasableSyntaxOnly?

Yes, if the code runs with type stripping, such as in Node.js without a build step. It reports problem syntax at compile time instead of at runtime.

## Related cards

- [Type Stripping](https://wonderium.dev/ts/type-stripping.md)
- [verbatimModuleSyntax](https://wonderium.dev/ts/verbatim-module-syntax.md)
- [enum](https://wonderium.dev/ts/enum.md)
- [namespace](https://wonderium.dev/ts/namespace.md)
- [Erased Types](https://wonderium.dev/ts/erased-types.md)

---

- Level: [TypeScript](https://wonderium.dev/ts.md)
- HTML version: https://wonderium.dev/ts/erasable-syntax-only
- Last updated: 2026-11-25
