# remove-types

> 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.

Latest version **1.0.0** (published 2022-02-07) · MIT license · 0 weekly downloads

## Install

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

## Health

**Score 30/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0 |
| Published | 2022-02-07 |
| First published | 2022-01-26 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 4 |
| Unpacked size | 17.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 3 |
| Author | Chris Freeman |
| Maintainers | cafreeman |
| Keywords | typescript, babel, types |

## Links

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

## Dependencies (4)

- [prettier](https://npm.io/package/prettier.md) ^2.5.1
- [@babel/core](https://npm.io/package/@babel/core.md) ^7.16.10
- [@babel/plugin-syntax-decorators](https://npm.io/package/@babel/plugin-syntax-decorators.md) ^7.16.7
- [@babel/plugin-transform-typescript](https://npm.io/package/@babel/plugin-transform-typescript.md) ^7.16.8

## 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

- 1.0.0 (latest) — 2022-02-07
- 0.0.1 — 2022-01-26

## README

# `remove-types`

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 '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/remove-types · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
