# Type Stripping

> The type stripping in TypeScript is a way to run TS code by removing type annotations without type checking.

## Can I run TypeScript directly in Node.js without compiling?

The process of running TS files by removing type annotations and leaving plain JS behind, without type checking. Node.js supports it natively, but only for erasable syntax, so `enum`, namespaces with code and parameter properties are not allowed.

- Topic: Basics
- Type: concept, process

## Example

Wrong:

```ts
import { User } from './types';

enum Role { Admin, User }

export const check = (u: User) => u.role === Role.Admin;
```

Right:

```ts
import type { User } from './types.ts';

const Role = { Admin: 'admin', User: 'user' } as const;

export const check = (u: User) => u.role === Role.Admin;
```

Type stripping needs `import type`, real '.ts' extensions and no `enum`, so an `as const` object replaces it.

## Common mistakes

- Type errors reach production because nothing ran the type checker.
- Path aliases from `tsconfig.json` fail at runtime, since stripping does not apply them.

## Key points

- Type checking still runs separately, e.g. `tsc --noEmit` in CI, since stripping skips it.
- Code uses only erasable syntax: no `enum`, parameter properties or runtime namespaces.
- Relative imports include the '.ts' extension, and type-only imports use `import type`.

## Interview questions

### Does type stripping check my types?

No. It only removes annotations. Run `tsc --noEmit` separately to catch type errors.

### Does Node.js type stripping read tsconfig.json?

No. Options like `paths` and `target` are ignored; Node only removes the type syntax.

### Can I use enum with type stripping?

Not with pure stripping, because `enum` creates runtime code. Use a union of literals or an `as const` object.

## Related cards

- [erasableSyntaxOnly](https://wonderium.dev/ts/erasable-syntax-only.md)
- [verbatimModuleSyntax](https://wonderium.dev/ts/verbatim-module-syntax.md)
- [import type](https://wonderium.dev/ts/type-only-imports.md)
- [tsc](https://wonderium.dev/ts/tsc.md)
- [Erased Types](https://wonderium.dev/ts/erased-types.md)

---

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