# TypeScript Transpiler

Paste TypeScript and convert it to best-effort JavaScript locally by stripping annotations, interfaces, assertions, and simple enums.

## Run it

- **CLI:** `gizza tool typescript-transpiler 'type User = { name: string }
export function greet(name: string): string {
  return `Hello ${name}` as string;
}'`
- **Web:** https://gizza.ai/tools/typescript-transpiler/
- **Agents:** machine-readable descriptor (parameters JSON Schema) at https://gizza.ai/tools/typescript-transpiler/tool.json

## Inputs

- `input` — TypeScript source _(field)_
- `enum_style` — Enum handling _(field)_
- `remove_comments` — Remove comments _(field)_

## Output

- JavaScript output (text)

## Query parameters

Open the tool pre-filled and auto-run via URL:

- `input` — TypeScript source
- `enum_style` — Enum handling
- `remove_comments` — Remove comments

Example: `https://gizza.ai/tools/typescript-transpiler/?input=type%20User%20%3D%20%7B%20name%3A%20string%20%7D%0Aexport%20function%20greet%28name%3A%20string%29%3A%20string%20%7B%0A%20%20return%20%60Hello%20%24%7Bname%7D%60%20as%20string%3B%0A%7D&enum_style=compile&remove_comments=true`

---

## What this tool does

This tool turns small TypeScript snippets into best-effort JavaScript by removing syntax that only exists for the type system. It strips annotations, interfaces, type aliases, `as`/`satisfies` assertions, optional markers, access modifiers, `implements` clauses, type-only imports/exports, and simple `enum` declarations.

The conversion runs locally in WebAssembly. It is useful for examples, docs, playground snippets, and quick migrations where you want readable JavaScript without starting a full TypeScript compiler.

## Example

Input:

```ts
type User = { name: string }
export function greet(name: string): string {
  const label: string = name as string;
  return `Hello ${label}`;
}
```

Output:

```js
export function greet(name) {
  const label = name;
  return `Hello ${label}`;
}
```

## Options

| Option | Choices | What it does |
| --- | --- | --- |
| **Enum handling** | `compile` (default), `strip` | Converts simple enums into JavaScript objects, or removes enum declarations entirely. |
| **Remove comments** | off (default), on | Removes `//` and `/* ... */` comments after normalizing line endings. |

## Limits and edge cases

This is a deterministic syntax stripper, not the official TypeScript compiler. It does not type-check, resolve modules, inline `const enum`, transform namespaces, emit decorator metadata, rewrite JSX, downlevel modern JavaScript, or guarantee correct output for every legal TypeScript program. For production builds, use `tsc`, Babel, SWC, or esbuild.

The input limit is 1 MB. The output preserves most original formatting, so already-minified input stays compact.

## FAQ

<details>
<summary>Is this the same as running tsc?</summary>

No. `tsc` parses the whole TypeScript language, type-checks when requested, resolves project settings, and can downlevel JavaScript. This tool is a fast local syntax stripper for snippets and simple files.

</details>

<details>
<summary>Does it support interfaces and type aliases?</summary>

Yes. Interface and type alias declarations are removed because they have no JavaScript runtime representation. References to those types in annotations are removed with the annotation.

</details>

<details>
<summary>What happens to enums?</summary>

By default, simple numeric enums are converted to JavaScript objects. If you choose `strip`, enum declarations are removed instead. Complex enum initializers are copied as object values but are not evaluated.

</details>

<details>
<summary>Can I use the output in production?</summary>

Use it as a preview or migration helper, then run your normal compiler and tests. The tool deliberately documents unsupported TypeScript features rather than pretending to be a complete compiler.

</details>

## Related tools

- [Code Chunker](https://gizza.ai/tools/code-chunker/): Split Python, Rust, JavaScript, TypeScript, Go, Java, C/C++, C#, PHP, or Swift into line-ranged chunks that keep functions and classes intact.
- [Code Formatter](https://gizza.ai/tools/code-formatter/): Beautify and re-indent minified or messy HTML, CSS, JavaScript, or JSON. Auto-detect the language, choose spaces or tabs, and format locally in your browser.
- [CSS Autoprefixer](https://gizza.ai/tools/css-autoprefixer/): Free online CSS autoprefixer — paste CSS and add the -webkit-, -moz-, -ms-, -o- vendor prefixes browsers still need. Runs entirely in your browser.
- [Directory Tree View](https://gizza.ai/tools/directory-tree-view/): Paste a du, find, or CSV file listing and get a clean indented tree with rolled-up folder sizes and file counts. Human, SI, or raw bytes. Free, in-browser.
- [Dotenv Manager](https://gizza.ai/tools/dotenv-manager/): Parse, validate, merge and secret-mask .env files in your browser: flag duplicate and missing keys, lint names, and export .env.example or JSON. No upload.
