# babel-remove-types

> > [!NOTE] > This is a fork of https://github.com/cafreeman/remove-types. It's not marked as a fork because we want pull requests to target this repo and not "upstream".

Latest version **2.0.0** (published 2026-03-20) · MIT license · 0 weekly downloads

## Install

```sh
npm install babel-remove-types
pnpm add babel-remove-types
yarn add babel-remove-types
bun add babel-remove-types
```

## Health

**Score 55/100 (C)** — status: active.

Positive: esm support; no vulnerabilities; has provenance.

Warnings: low downloads; no types.

## Facts

| | |
|---|---|
| Version | 2.0.0 |
| Published | 2026-03-20 |
| First published | 2024-09-27 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM |
| Dependencies | 4 |
| Unpacked size | 13.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Provenance | attested (GitHub Actions) |
| GitHub stars | 0 |
| Maintainers | real_ate |
| Keywords | typescript, babel, types |

## Links

- npm: https://www.npmjs.com/package/babel-remove-types
- Repository: https://github.com/ember-cli/babel-remove-types
- Homepage: https://github.com/ember-cli/babel-remove-types#readme
- Issues: https://github.com/ember-cli/babel-remove-types/issues
- npm.io page: https://npm.io/package/babel-remove-types

## Dependencies (4)

- [prettier](https://npm.io/package/prettier.md) ^3.8.1
- [@babel/core](https://npm.io/package/@babel/core.md) ^7.29.0
- [@babel/plugin-syntax-decorators](https://npm.io/package/@babel/plugin-syntax-decorators.md) ^7.28.6
- [@babel/plugin-transform-typescript](https://npm.io/package/@babel/plugin-transform-typescript.md) ^7.28.6

## Alternatives

- [@openai/codex-sdk](https://npm.io/package/@openai/codex-sdk.md) — 731.4K weekly downloads
- [babel-plugin-transform-react-jsx](https://npm.io/package/babel-plugin-transform-react-jsx.md) — 565.0K weekly downloads
- [babel-helper-remove-or-void](https://npm.io/package/babel-helper-remove-or-void.md) — 508.5K weekly downloads
- [@pnpm/store-controller-types](https://npm.io/package/@pnpm/store-controller-types.md) — 186.9K weekly downloads
- [react-native-signature-canvas](https://npm.io/package/react-native-signature-canvas.md) — 155.6K weekly downloads

## Recent versions

- 2.0.0 (latest) — 2026-03-20
- 1.1.0 — 2026-01-05
- 1.0.2 — 2025-10-09
- 1.0.1 — 2025-01-29
- 1.0.0 — 2024-09-27

## README

# `babel-remove-types`

> [!NOTE]
> This is a fork of https://github.com/cafreeman/remove-types. It's not marked as a fork because we want pull requests to target this repo and not "upstream".

A small library for transforming TypeScript code into JavaScript code in the least destructive way possible. This library exports a single function whose purpose is to preserve everything else about the code except for the actual TypeScript syntax itself. As a result, things like decorators and class fields should pass straight through without being transformed in any way.

## Usage

```js
import { removeTypes } from 'babel-remove-types';

const original = `
type AnimalType = 'cat' | 'dog';

// An interface for animals (this comment should be removed when transformed)
interface Animal {
  type: AnimalType;
  name: string;
  age: number;
}

class Cat implements Animal {
  type: AnimalType = 'cat';
  name: string;
  age: number;

  constructor(name: string, age: number) {
    // This is the name of the animal (this comment should stay)
    this.name = name;
    this.age = age;
  }
}
`;

console.log(await removeTypes(original));

/*
class Cat {
  type = 'cat';

  constructor(name, age) {
    // This is the name of the animal (this comment should stay)
    this.name = name;
    this.age = age;
  }
}
*/
```

## API

### `removeTypes(code, prettierConfig = true): Promise<string>`

- `code`: A string containing TypeScript code
- `prettierConfig`:

  - defaults to `true`
  - By default, `removeTypes` will run Prettier with a very basic config on the transformed code before returning it. This allows us to clean up some of the "low-hanging" fruit leftover from the Babel transform, e.g. newlines at the beginning or end of the file.
  - If you'd prefer to not run Prettier _at all_, passing `false` will bypass the Prettier pass entirely.
  - If you'd prefer to use your own Prettier configuration, you can pass an object containing [Prettier configuration options](https://prettier.io/docs/en/options.html) and `removeTypes` will use it instead.

- returns `Promise<string>`: a string containing the transformed JavaScript output.

## Acknowledgements

This library is heavily indebted to [cyco130/detype](https://github.com/cyco130/detype) and began as an extraction and refactor of one of its core functions.

---
_Source: https://npm.io/package/babel-remove-types · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
