Skip to content
Tutorials Center
My learning

Topics

TypeScript Reference ยท Concepts and Comparisons

Linting and formatting TypeScript

How the TypeScript compiler, typescript-eslint and Prettier divide the work, with a flat ESLint config, useful rules, type-aware linting and CI order.

Three tools usually sit beside each other in a TypeScript project, and each answers a different question. The compiler asks "do the types fit together?" A linter asks "is this code likely to be a bug or against our conventions?" A formatter asks "how should this code look?" Keeping the jobs separate avoids arguments and duplicated rules.

The standard linter setup is ESLint with the typescript-eslint package. The standard formatter is Prettier, or the formatter built into your toolchain (Biome and others work too). Lint rules that only care about style should be switched off in favor of the formatter.

JavaScript
// eslint.config.js (flat config, read-only example)
import eslint from "@eslint/js";
import tseslint from "typescript-eslint";

export default tseslint.config(
  eslint.configs.recommended,
  ...tseslint.configs.strictTypeChecked,
  {
    languageOptions: {
      parserOptions: { projectService: true, tsconfigRootDir: import.meta.dirname },
    },
  },
);

Try it

TypeScript What a floating promise looks like

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with node:readline or readFileSync(0)), it gets the next line from this box.

TypeScript Compiler errors versus lint warnings

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with node:readline or readFileSync(0)), it gets the next line from this box.

Who checks what

Concern Tool
Types, nulls, missing properties tsc
Probable bugs the type system allows (floating promises, unsafe any, ==) ESLint with typescript-eslint
Naming, import order, banned APIs ESLint
Indentation, quotes, line width, trailing commas Prettier (or Biome)

Type-aware linting

Some rules need type information, for example no-floating-promises, no-unsafe-assignment, no-misused-promises and switch-exhaustiveness-check. They require parserOptions.projectService (or the older project) so ESLint can ask the TypeScript program about each node. These rules are slower than syntax-only ones, so run them in CI and let the editor run them in the background.

Useful presets, from lightest to strictest: recommended, recommended-type-checked, strict, strict-type-checked, plus the stylistic presets for consistency rules.

Usage notes

  • Lint config files are JavaScript or TypeScript, not tsconfig. Flat config (eslint.config.js) is the current format.
  • Disable formatting rules in ESLint (eslint-config-prettier) so the two tools never fight.
  • @ts-expect-error is lintable. The ban-ts-comment rule can require a description after the directive.
  • Order in CI: format check, lint, tsc --noEmit, tests. Cheap checks first.
  • Do not copy the compiler. Rules that duplicate noUnusedLocals or strictNullChecks only add noise.
  • Lint test files separately if they need relaxed rules, for example allowing non-null assertions.
  • Prettier does not change code meaning, only layout, so reformat in its own commit to keep blame readable.