TypeScript Formatter Online
WM-90Paste TypeScript and get it back with clean indentation, wrapped lines and consistent quotes and semicolons. It runs Prettier's TypeScript parser in your browser.
Runs in your browser. Nothing is uploaded.
TypeScript
Formatted TypeScript
How to use it
- Paste your TypeScript, or open a .ts file or drop it on the input box.
- Choose the indent, line width, semicolons and quote style.
- Press Format.
- Copy the result or download it as a .ts file.
What the TypeScript parser reads
The parser is the TypeScript compiler's own, so interfaces, type aliases, unions, generics, enums, abstract classes, decorators, type assertions and import type all work. Output keeps your types exactly and only moves layout. Union types that are too wide for a line are broken across lines with a leading bar, and long function signatures wrap one parameter per line.
Formatting is not type checking
The tool never runs the type checker. A wrong type, a missing property or an unused variable will not be reported, and the code is never executed. Only syntax the parser rejects produces an error, with a line and column. Treat a clean result as a sign the file is readable, not that it compiles.
JSX and .tsx files
Angle brackets mean generics in .ts files and elements in .tsx files, and a parser has to choose one. This page chooses generics, so JSX inside the input will fail. Output also follows the Prettier version in this page, which may not match the one in your repository.
Error messages and what to do
| Message | What it means | Fix |
|---|---|---|
Could not format the TypeScript: Type expected at line 1, column 8. | A type was required after the colon but none was found. | Add the missing type at the line and column shown, then format again. |
Questions people ask
How do I format TypeScript code online?
Paste the code into the box, pick your indent and quote style, and press Format. The result appears in the output box, ready to copy or download as a .ts file.
Does it work with interfaces and generics?
Yes. Interfaces, generic functions and classes, mapped and conditional types, enums and decorators are all parsed. Long type unions and signatures are wrapped at the line width you choose.
Will it find type errors?
No. It formats the text without running the type checker. Only syntax errors are reported. Use tsc or your editor for type errors. Use tsc or your editor for type errors; a clean result here only means the syntax is readable.
Can I format React TSX here?
Not reliably. The parser used here treats angle brackets as generics, so JSX elements cause a syntax error. Use the Babel formatter for plain JSX, or run Prettier in your project for TSX.
Why are my quotes and semicolons changed?
Those are options. Semicolons are added by default and double quotes are used unless you tick single quotes. Untick semicolons if your project uses a no-semicolon style.
About this tool
Formats TypeScript with Prettier and the TypeScript parser. Interfaces, generics, enums, decorators, type assertions and import type are supported. Only layout changes: spacing, line breaks, quotes and semicolons follow your options, and comments stay. It does not type-check, so type errors are not reported; only syntax the parser rejects gives an error with a line and column. JSX in a .tsx file is not accepted by this page, because generic arrow functions and JSX use the same angle brackets. Output follows the Prettier version in this page.