TypeScript Formatter
Format and beautify TypeScript and TSX online with Prettier, including types, generics and decorators. Choose indentation, quotes and semicolons.
Runs in your browser · Nothing uploadedFree · No sign-up
Something not working, or missing a feature? Send feedback
About the TypeScript Formatter
The TypeScript Formatter formats .ts and .tsx code with Prettier, including type annotations, generics, enums and decorators.
Everything runs in your browser, so your input is never uploaded to a server.
How to use the TypeScript Formatter
- Paste TypeScript or TSX, or open a file.
- Choose indentation, quotes and semicolons.
- Copy or download the formatted code.
Example
Input
export class UserService{constructor(private readonly repo:Repo<User>){}
async find(id:number):Promise<User|null>{const user=await this.repo.get(id);return user??null}}
type Role="admin"|"editor"|"viewer"Result
export class UserService {
constructor(private readonly repo: Repo<User>) {}
async find(id: number): Promise<User | null> {
const user = await this.repo.get(id);
return user ?? null;
}
}
type Role = 'admin' | 'editor' | 'viewer';
Formatted with the defaults: two-space indentation, single quotes and semicolons. Type annotations, generics and union types are spaced consistently.
Common mistakes
- Expecting type errors. The formatter only checks syntax. Code that formats cleanly can still have type errors; run it through the TypeScript Compiler to see them.
- Different settings from your project. If your repository has a .prettierrc, match its quote, semicolon and width settings here, or the formatted code will show up as a large diff.
- Angle-bracket casts in TSX. In .tsx files <User>value is read as JSX and fails to parse. Use value as User instead, which works in both .ts and .tsx.
Works well with the TypeScript Formatter
- TypeScript Compiler: type-check and run the formatted code.
- JSON to TypeScript: generate interfaces from a JSON response.
- JavaScript Formatter: format plain JavaScript files with the same settings.
Frequently asked questions
Does formatting type-check my code?
No. Formatting only needs valid syntax. Use the TypeScript Compiler tool to see type errors.
Is TSX supported?
Yes, JSX inside TypeScript files is formatted too.
Are decorators and enums supported?
Yes. Decorators, enums, namespaces, abstract classes, satisfies and other TypeScript-only syntax are formatted.
Does it sort imports?
No. Like Prettier itself, it never reorders code, so formatting cannot change behaviour.
Guides and tutorials
- Programming Languages
TypeScript Strict Mode Explained: Every Flag and the Bugs It Catches
What "strict": true turns on, the real compiler error for each flag, extra checks worth enabling, and a step-by-step plan for migrating an existing codebase.
· 5 min read
- Code Quality & Workflow
Why Code Formatting Matters: Setting Up Prettier for Your Team
Why consistent formatting speeds up reviews, how Prettier works, and a team setup: config, format on save, CI, ESLint and reformatting a codebase safely.
· 5 min read
Related tools
JSON Formatter
Format and beautify JSON with configurable indentation and optional key sorting. Errors are reported with exact line and column.
HTML Formatter
Format and beautify messy or minified HTML into clean, indented markup with Prettier, including embedded CSS and JavaScript. Runs locally in your browser.
CSS Formatter
Format and beautify CSS, SCSS and Less online with Prettier. Turn minified or messy stylesheets into readable, consistently indented code in your browser.
JavaScript Formatter
Format and beautify JavaScript and JSX online with Prettier. Choose indentation, quotes, semicolons and line width; your code is formatted in your browser.
PHP Formatter
Format PHP code online with Prettier for PHP (@prettier/plugin-php): PSR-12 braces, spacing and 4-space indentation. No install, and nothing is uploaded.
SQL Formatter
Format and beautify SQL queries online for MySQL, PostgreSQL, SQLite, SQL Server and more, with keyword casing and indentation options. Runs in your browser.