Skip to content
Devtoolry

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

  1. Paste TypeScript or TSX, or open a file.
  2. Choose indentation, quotes and semicolons.
  3. Copy or download the formatted code.

Example

Tidy a cramped service

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

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