# TypeScript Formatter

Tidy up TypeScript code with this TypeScript Formatter. Paste interfaces, types, enums, generics, classes or functions and the tool reflows them token by token with two space indentation, a space after type annotation colons and around operators, one member per line in blocks and enums, and semicolons at statement ends. Ideal for developers cleaning up snippets, generated code or pasted examples before sharing or reviewing.

## Frequently asked questions

### How does the TypeScript Formatter work?

It reads your code as a stream of tokens, such as braces, semicolons, operators, strings and comments, and rebuilds the layout from them. Braces open indented blocks, semicolons end lines and operators get consistent spacing.

### Does it check my TypeScript for errors?

No, it neither type checks nor validates syntax, so it also formats incomplete snippets. Run tsc or your editor's checks when you need to know whether the code compiles.

### How are interfaces and enums formatted?

Interface and class bodies get one member per line with two space indentation and a semicolon after each member. Enum members are placed one per line with a trailing comma after each, including the last.

### Are generics kept intact?

Yes, angle brackets of generics such as Array<T> or Map<string, T> are tracked so they are not treated as comparison operators. Spaces after commas inside the brackets are normalized.

### What indentation does it use?

Blocks are indented with two spaces and there are no options to change this. Short object literals after an assignment or a return stay on a single line.

### Are comments preserved?

Yes. Line comments end their line and the code continues below them, and block comments are kept where they appear.

### Are strings and template literals changed?

No, string literals, template literals and regular expressions are copied exactly as written. Only the whitespace between tokens is rearranged.

### Will formatting change how my code behaves?

The formatter only changes whitespace and adds missing semicolons at statement ends. Review the result if your code relies on automatic semicolon insertion in unusual places, such as a line that starts with a parenthesis.

### Why is the output wrapped in a typescript code fence?

The result comes back as a Markdown code block marked typescript so it renders highlighted in Markdown, issues and chat. Copy the lines between the fences for a .ts file.

### How large can my code be?

You can format up to 5 MB of code in one run, and larger input is rejected with a message. The result is the same as the TypeScript option of the Code Formatter.

Your ad here?

[Email us](mailto:hi@dennn.is?subject=Advertising%20on%20OneClick%20Pro)

[Ad The agent-ready plugin suite for WordPress.](https://sleekwp.com/?ref=oneclickpro)
