Home › Developer Tools › TypeScript Formatter

TypeScript Formatter

Paste TypeScript or TSX and get clean, consistently formatted code from Prettier, the formatter most TypeScript projects use. Pick the print width, indentation, semicolons and quote style; syntax errors are shown with the exact line and column.

Last updated:

Loading the Prettier formatter…

Tip: press Ctrl + Enter to format; Tab indents inside the editor (press Esc first to move focus). Formatting runs locally with Prettier; your code is never uploaded.

Advertisement
Advertisement

How to use the TypeScript Formatter

  1. Paste your code into the TypeScript input, open a .ts or .tsx file, or load a sample.
  2. Pick the style: print width, indentation, quotes, trailing commas, semicolons and arrow parentheses.
  3. Press Format TypeScript (or Ctrl + Enter). With Format as I type on, the output refreshes while you edit.
  4. Fix syntax errors if shown: the message gives the line and column, and Show in input jumps to the spot.
  5. Copy or download the formatted code, or press Use output as input to keep editing it.

Prettier options and their .prettierrc names

Every option in the tool maps to a Prettier setting, so you can copy your choices into a .prettierrc file and get identical output in your editor and CI:

Option in this tool.prettierrc keyDefaultEffect
Print widthprintWidth80Line length the printer tries to fit code into.
IndentationtabWidth, useTabs2, falseSpaces per level, or tab characters.
SemicolonssemitrueOff prints no semicolons and adds a leading ; only where ASI would break the code.
QuotessingleQuotefalsePrettier still picks the quote that needs fewer escapes.
Trailing commastrailingComma"all""all", "es5" or "none" in multi-line lists.
Spaces in bracesbracketSpacingtrue{ a, b } versus {a, b}.
Arrow parensarrowParens"always"(x) => x versus x => x.

Example .prettierrc: { "printWidth": 100, "singleQuote": true, "trailingComma": "all" }

Common TypeScript syntax errors

  • ',' expected or ')' expected: a missing comma between parameters or object members, or a bracket that was never closed.
  • '}' expected: a block, class or interface body is not closed; the reported line is often at the end of the file, so look upward for the opening brace.
  • Unterminated string literal: a quote is missing, or curly quotes (“ ”) were pasted from a document. Template literals use backticks.
  • JSX element has no corresponding closing tag: in TSX every element must be closed, including void elements such as <br /> and <input />.
  • Expression expected on a <: the file contains JSX but is being parsed as plain .ts. Select TSX.

Only want to know whether plain JavaScript parses? Use the JavaScript Syntax Checker. Generating interfaces from an API response? Try JSON to TypeScript.

Frequently asked questions

Is my code uploaded to a server?

No. Prettier and its TypeScript parser are downloaded once as JavaScript files and run inside your browser tab. The code you paste is never sent anywhere, so it is safe for private or proprietary source.

Does this produce the same output as Prettier in VS Code?

Yes, as long as the options match. The tool runs Prettier 3 with the typescript parser, the same engine used by the Prettier VS Code extension and the prettier command line. Set the same print width, tab width, quotes, semicolons and trailing comma values as your .prettierrc.

Does the formatter check types?

No. It parses the syntax and reprints it; it does not run the TypeScript compiler's type checker. Code with type errors such as a wrong argument type is formatted normally, while code with syntax errors such as a missing bracket is rejected with the error location.

How do I format TSX or React components?

Choose TSX / React (.tsx), or leave Language on Auto: if the code contains JSX the tool parses it as TSX. Note that the old <Type>value type assertion syntax is not allowed in .tsx files; use value as Type instead.

What does print width do?

Print width is the line length Prettier tries to stay within. It is a target, not a hard limit: long strings, URLs or deeply nested code can exceed it. 80 is Prettier's default; many teams use 100 or 120.

What is the difference between the trailing comma options?

All (Prettier 3's default) adds trailing commas wherever TypeScript allows them, including function parameters and type parameter lists. ES5 adds them only in arrays and objects. None removes them. Trailing commas make git diffs cleaner when items are added.

Why are some of my blank lines or comments kept?

Prettier preserves single blank lines between statements and keeps comments, because they carry meaning for readers. Multiple blank lines are collapsed into one.

Are all the tools on FreeToolCabin tested for quality and accuracy?

Yes! Every tool on our site undergoes automated Q/A testing in real browser environments to ensure high precision, correct output, and zero errors. If you happen to spot a bug or have a suggestion, please contact us at [email protected] and our team will review it right away.

Related tools

JavaScript BeautifierFormat and beautify messy or minified JavaScript, or minify it.JavaScript Syntax CheckerCheck JavaScript for syntax errors with line and column, for any ES version, script or module.JSON to TypeScriptGenerate TypeScript interfaces or types from JSON, with nested types and optional fields.Code Diff CheckerCompare two code files side by side or unified, with syntax colors and changes highlighted.JSON FormatterBeautify, minify and validate JSON, with a collapsible tree view.SQL Formatter & BeautifierFormat, beautify or minify SQL queries for MySQL, PostgreSQL and more.HTML FormatterBeautify and indent HTML code with a live preview.CSS FormatterBeautify CSS with indent controls and optional property sorting.XML FormatterBeautify, validate and minify XML with a collapsible tree view.ZIP File CreatorCompress files and folders into a ZIP.YAML Validator & FormatterValidate, format and minify YAML, and convert YAML to JSON or back.HTML MinifierMinify HTML: strip comments and whitespace safely and see how many bytes you save.CSS MinifierMinify CSS with csso or a built-in engine and see the size saved instantly.JavaScript MinifierMinify JavaScript with Terser: compress, mangle and see how many bytes you save.JSON MinifierMinify and validate JSON, sort keys and see exactly how many bytes you save.IPv6 Expander & CompressorExpand IPv6 addresses to full form or compress them per RFC 5952, one or many at once.GraphQL FormatterPretty-print and indent GraphQL queries, mutations and schemas, or minify them, instantly.CSS ValidatorValidate CSS: syntax errors, unknown properties and invalid values by line, plus auto-fix.Gzip Compress / DecompressGzip or deflate text and files, get Base64 output, and decompress Base64 or .gz files.IBAN ValidatorCheck an IBAN's mod-97 checksum, country and length, and see its bank code and account parts.JSON Schema ValidatorValidate JSON against a JSON Schema (draft-07, 2019-09, 2020-12) with clickable error paths.Markdown FormatterBeautify Markdown with Prettier: list markers, prose wrap, aligned tables and live preview.PHP FormatterBeautify PHP code with Prettier PHP: PSR-12 style, indent and brace options, syntax errors.XML MinifierMinify and validate XML: strip whitespace and comments, keep CDATA, see the size savings.C# FormatterBeautify C# code online: Allman or K&R braces, indent size and line width, clang-format option.HTML ValidatorCheck HTML for errors and warnings with line numbers, locally or with the W3C Nu checker.Java FormatterBeautify Java code online: indent size, brace style and line width, with clang-format option.JavaScript ObfuscatorObfuscate JavaScript with string encoding, renaming and control-flow flattening presets.Phone Number FormatterFormat and validate lists of phone numbers to E.164, international or national style.Python FormatterFormat Python code in Black/Ruff style: line length, quote style, indent, copy or download.Responsive Design CheckerPreview any website at phone, tablet, laptop and desktop sizes side by side, with rotate and zoom.Browser Compatibility CheckerSearch CSS, JavaScript and HTML features and see which browser versions support them.Core Web Vitals CheckerCheck real-user LCP, INP and CLS for any URL or site and see if it passes Core Web Vitals.Heading Structure CheckerPaste HTML to see its H1-H6 outline and catch missing H1s, multiple H1s and skipped levels.Website Hosting CheckerFind out who hosts a website: hosting provider, IP addresses, ASN, network owner and location.Routing Number ValidatorCheck a US ABA routing number's checksum and format and see its Federal Reserve district.Spam Word CheckerScan an email subject and body for spam trigger words, excess caps, exclamation marks and risky links.Check Digit CalculatorCalculate or validate check digits for UPC, EAN, GTIN, SSCC, ISBN, ISSN and mod 11 codes.XSD ValidatorValidate XML against an XSD schema in your browser and see each error with its line number.Strftime Format BuilderBuild Python and C strftime format strings by clicking tokens, with a live preview and reference.Luhn Algorithm CheckerValidate numbers with the Luhn mod 10 check or calculate the missing check digit, step by step.
See all 41 Code Formatters & Validators →