Skip to content
Categories
TypeScript Formatter
Format TypeScript to make it easier to read.
Overview
- Formats TypeScript packed into a single line into a readable form, using Prettier.
- Handles code containing TypeScript-specific type annotations, such as interfaces, type aliases, and generics.
- Uses the same Prettier engine as JavaScript Formatter, switching only the parser to the TypeScript one.
Usage
- Enter the TypeScript you want to format into the text area.
- Click the "Format" button.
- The result, formatted according to Prettier's rules, is displayed below. Use the "Copy" button to copy it to the clipboard.
Example
Input
interface Foo{a:string;b:number}Output
interface Foo {
a: string;
b: number;
}Use Cases
- Formatting minified TypeScript code into a readable form for debugging
- Unifying the indentation of a type definition file (.d.ts) or code copied from elsewhere to match your project's style
- Formatting a type definition or logic snippet into a consistent style before including it in a code review
FAQ
Is the TypeScript I enter sent anywhere?
No. Formatting runs entirely in your browser using Prettier; nothing is sent to an external server.
What happens if there is a syntax error?
An error message "The TypeScript syntax is invalid." is displayed along with details.
Is the processing shared with the JavaScript Formatter?
Yes. The formatting engine (Prettier standalone) invocation is shared, and only the parser differs between tools.
Notes
- Formatting fails if the TypeScript is syntactically invalid.
- No type checking (type error detection) is performed. This tool only formats syntax.
- Formatting very large code may make browser processing slow.
Related Tools
Format JavaScript to make it easier to read.
Generate TypeScript type definitions from JSON.
Format HTML to make it easier to read.