Skip to main content
CaseSwitch

TypeScript Formatter

Use the CaseSwitch TypeScript Formatter to pretty-print types, interfaces, and TS snippets for reading. Paste the code, copy the formatted result. Formatting runs in this browser with Prettier’s TypeScript parser — nothing is uploaded.

Written by the CaseSwitch editorial team. We maintain these tools in the browser so drafts, keys, and images stay on your device.

Last reviewed: 23 July 2026

Processed locally in your browser. Nothing is sent to a server.

Paste or type text to convert. Output stays empty until there is input.

Character count: 0 · Word count: 0 · Line count: 0

Examples

Type alias spacing

Input

type User={id:string;name:string}

Output

type User = { id: string; name: string };

Interface with array field

Input

interface User{id:string;roles:string[]}

Output

interface User {
  id: string;
  roles: string[];
}

Generic function

Input

function identity<T>(value:T):T{return value}

Output

function identity<T>(value: T): T {
  return value;
}

Union type

Input

type Status='idle'|'loading'|'error'

Output

type Status = "idle" | "loading" | "error";

Simple const assertion-style object

Input

const cfg={retry:3,debug:false}

Output

const cfg = { retry: 3, debug: false };

How to use

  1. Paste a TypeScript snippet (type, interface, or short module fragment).
  2. Review the indented output; fix parse errors if formatting fails.
  3. Copy the result into your PR or notes.

What this tool is for

Dense generics and one-line interfaces are hard to review in a ticket. This page normalizes whitespace and wrapping while preserving type syntax the parser understands. It is a formatter, not tsc — invalid types can still format if the syntax parses.

How it works

Pretty mode runs Prettier with the TypeScript parser. Indent follows your tab width setting (default 2). Minify collapses whitespace with a simple pass. Exotic experimental syntax may fail to parse.

When to use it

Cleaning a type copied from a library .d.ts, reviewing a generic-heavy snippet, preparing a PR comment, and normalizing a short TSX-ish example.

When not to use it

Not a typechecker. Not a compiler to JavaScript. Plain JS without types can use the JavaScript Formatter. JSON belongs on the JSON Formatter.

How it compares to related tools

JavaScript Formatter for plain JS. JSON Formatter for data. Repo `tsc` and ESLint remain the authorities for correctness.

Common mistakes

Expecting `any` to be flagged. Pasting a whole tsconfig project. Assuming format failure means a type error (it is usually syntax).

Format is not typecheck

Prettier will happily format a type that tsc would reject, as long as the syntax is parseable. Run your IDE or `tsc --noEmit` for real errors. Conversely, a format failure usually means broken syntax, not a semantic type mismatch.

TSX and project config

Simple component snippets often format. Edge-case JSX and project-specific path aliases are better handled in your editor with the repo Prettier config. This page does not load your tsconfig.

Frequently asked questions

Does formatting check types?+

No. Invalid types can still format if the syntax is parseable. Run tsc or your IDE for errors.

Is TSX supported?+

Simple component snippets often format; edge-case JSX may need your editor.

Will it match my repo Prettier?+

Defaults may differ from your shared config. Use CI Prettier for the canonical format.

Can I compile TypeScript to JavaScript here?+

No. This page only reformats TypeScript source text.

Is my code uploaded?+

No. Formatting runs in this browser.

Why did quotes change?+

Prettier applies its default quote style. Match your repo config locally if that matters for the diff.

Does this tool send my payload to CaseSwitch?+

No. Formatting, encoding, and naming conversions for this page run in your browser after load — your sample stays on the device.

Related tools