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
- Paste a TypeScript snippet (type, interface, or short module fragment).
- Review the indented output; fix parse errors if formatting fails.
- 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
JavaScript Formatter
Reading a minified function from DevTools, cleaning a gist, sharing a snippet in a ticket, and normalizing a short example before a PR comment.
JSON Formatter
Debugging a 401 response, comparing two configs, preparing a gist, shrinking a JSON blob before embedding it in a test fixture, and checking whether a file is actually JSON before you commit it. If you need to escape a string as a JSON literal, use JSON Stringify instead. If you need YAML, use JSON to YAML after the JSON is valid.
GraphQL Formatter
Cleaning a query copied from a network tab, sharing a fragment in a PR, teaching selection sets, and normalizing a mutation before documentation.
HTML Formatter & Minifier
Cleaning an email HTML snippet, reviewing a CMS export, shrinking a static fragment for a demo, and making a nested list readable before you edit it by hand.
CSS Formatter
Inspecting a production CSS file, cleaning a snippet from Stack Overflow, teaching cascade with readable examples, and preparing a small style review.
SCSS Formatter
Cleaning a mixin you copied, reviewing a theme file fragment, preparing a style PR comment, and teaching nesting with a readable example.
XML Formatter
Debugging an API that still speaks XML, cleaning an SVG you will edit by hand, reading a Maven pom snippet, and comparing two responses visually.