TypeScript Formatter
Paste TypeScript and get it formatted with consistent style.
INPUT
CHARS: 0WORDS: 0LINES: 0
OUTPUT
CHARS: 0WORDS: 0LINES: 0
How the TypeScript Formatter works
The code is parsed with the TypeScript parser and printed with Prettier's rules, which cover type annotations, interfaces, union and intersection types, generics, enums, abstract classes, decorators and JSX in TSX files.
Options for indentation, quote style and semicolons let you match the conventions of your project. Parse errors are reported with their position.
TypeScript Formatter examples
Format TypeScript interface and function
Input
interface Config{id:string;active:boolean;}function run(c:Config):string{return c.id;}Result
interface Config { id: string; active: boolean; } function run(c: Config): string { return c.id; }
When it is useful
- •Formatting a snippet before posting it to an issue or forum.
- •Making generated type definitions readable.
- •Quickly checking that a type declaration parses.
- •Applying a team style to code outside a configured project.
Frequently Asked Questions
Does it type check my code?
No. It checks syntax only, not whether types are correct.
Does it work with decorators and enums?
Yes, along with abstract classes, namespaces and other TypeScript specific syntax.
Can it format plain JavaScript?
TypeScript is a superset, so valid JavaScript works too, though the JavaScript Formatter is the more direct choice.
Related tools
- JavaScript FormatterMake minified or messy JavaScript readable.
- JSON Formatter and MinifierPaste JSON to validate it and print it neatly, or compress it to a single line.
- GraphQL FormatterPaste a GraphQL document and get it laid out cleanly.
- HTML Formatter, Minifier and BeautifierClean up markup, or squeeze it down for production.