Skip to main content

Lesson 4 of 8

ESLint + Prettier for TypeScript

ESLint with `@typescript-eslint` enforces code quality rules that TypeScript's compiler doesn't catch - unused variables, unsafe type patterns, naming conventions, and more. Prettier handles formatting automatically. Together they create a consistent, high-quality TypeScript codebase.

12 minBy Priygop Editorial TeamUpdated 2026Peer Reviewed & Verified

ESLint + Prettier - Professional TypeScript Config

ESLint + Prettier - Professional TypeScript Config
# ── Installation ─────────────────────────────────────────────
npm install --save-dev \
  eslint \
  @typescript-eslint/parser \
  @typescript-eslint/eslint-plugin \
  eslint-config-prettier \
  prettier

# ── eslint.config.ts (flat config, ESLint 9+) ─────────────────
import tseslint from "@typescript-eslint/eslint-plugin";
import tsParser from "@typescript-eslint/parser";

export default [
  {
    files: ["**/*.ts", "**/*.tsx"],
    languageOptions: {
      parser: tsParser,
      parserOptions: {
        project: "./tsconfig.json",   // type-aware linting
        tsconfigRootDir: __dirname,
      },
    },
    plugins: { "@typescript-eslint": tseslint },
    rules: {
      // ── Safety rules ────────────────────────────────────────
      "@typescript-eslint/no-explicit-any":             "error",
      "@typescript-eslint/no-unsafe-assignment":        "error",
      "@typescript-eslint/no-unsafe-call":              "error",
      "@typescript-eslint/no-unsafe-return":            "error",
      "@typescript-eslint/no-floating-promises":        "error",  // await every Promise!
      "@typescript-eslint/await-thenable":              "error",
      "@typescript-eslint/no-unnecessary-type-assertion":"warn",

      // ── Quality rules ────────────────────────────────────────
      "@typescript-eslint/consistent-type-imports":     ["error", { prefer: "type-imports" }],
      "@typescript-eslint/no-unused-vars":              ["error", { argsIgnorePattern: "^_" }],
      "@typescript-eslint/prefer-nullish-coalescing":   "warn",
      "@typescript-eslint/prefer-optional-chain":       "warn",
      "@typescript-eslint/no-non-null-assertion":       "warn",
      "no-console":                                    ["warn", { allow: ["warn", "error"] }],
    },
  },
];

# ── .prettierrc ─────────────────────────────────────────────────
// {
//   "semi": true,
//   "singleQuote": false,
//   "printWidth": 100,
//   "tabWidth": 2,
//   "trailingComma": "all",
//   "arrowParens": "always"
// }

# ── package.json scripts ─────────────────────────────────────
// "scripts": {
//   "lint":        "eslint src --ext .ts,.tsx",
//   "lint:fix":    "eslint src --ext .ts,.tsx --fix",
//   "format":      "prettier --write "src/**/*.{ts,tsx}"",
//   "format:check":"prettier --check "src/**/*.{ts,tsx}"",
//   "check":       "tsc --noEmit && npm run lint && npm run format:check"
// }

Common Mistakes

  • Not enabling type-aware rules - most powerful `@typescript-eslint` rules (like `no-floating-promises`) require `parserOptions.project`. Without it, you get a much weaker set of checks.
  • Running Prettier after ESLint manually - use `eslint-config-prettier` to disable ESLint formatting rules, and let Prettier own formatting. Never configure spacing/semicolons in both.
  • Disabling `no-explicit-any` globally - when a file legitimately needs `any` (third-party JS interop), use an inline `// eslint-disable-next-line` with a reason comment. Disabling globally defeats the purpose.

Tip

Tip

Practice ESLint Prettier for TypeScript in small, isolated examples before integrating into larger projects. Breaking concepts into small experiments builds genuine understanding faster than reading alone.

Diagram
Loading diagram…

Visual architecture and concepts for ESLint + Prettier for TypeScript

Practice Task

Note

Practice Task - (1) Write a working example of ESLint Prettier for TypeScript from scratch without looking at notes. (2) Modify it to handle an edge case (empty input, null value, or error state). (3) Share your solution in the Priygop community for feedback.

Quick Quiz

Common Mistake

Warning

A common mistake with ESLint Prettier for TypeScript is skipping edge case testing - empty inputs, null values, and unexpected data types. Always validate boundary conditions to write robust, production-ready typescript code.

Key Takeaways

  • ESLint with `@typescript-eslint` enforces code quality rules that TypeScript's compiler doesn't catch - unused variables, unsafe type patterns, naming conventions, and more.
  • Not enabling type-aware rules - most powerful `@typescript-eslint` rules (like `no-floating-promises`) require `parserOptions.project`. Without it, you get a much weaker set of checks.
  • Running Prettier after ESLint manually - use `eslint-config-prettier` to disable ESLint formatting rules, and let Prettier own formatting. Never configure spacing/semicolons in both.
  • Disabling `no-explicit-any` globally - when a file legitimately needs `any` (third-party JS interop), use an inline `// eslint-disable-next-line` with a reason comment. Disabling globally defeats the purpose.

Hands-on Practice Tools for this Course

Test what you learn using these free in-browser developer utilities (no signup required).

All 40+ Tools

Topics in This Module

0/8 done