ESLint with typescript-eslint

Linting TypeScript

The compiler checks types; ESLint with typescript-eslint catches bad patterns: floating promises, unnecessary conditions, any, unused variables. The type-checked configs use type information for the most valuable rules.

Example

npm install --save-dev eslint @eslint/js typescript-eslint
// eslint.config.mjs (flat config)
import eslint from "@eslint/js";
import tseslint from "typescript-eslint";

export default tseslint.config(
  eslint.configs.recommended,
  tseslint.configs.strictTypeChecked,
  tseslint.configs.stylisticTypeChecked,
  {
    languageOptions: { parserOptions: { projectService: true, tsconfigRootDir: import.meta.dirname } },
    rules: {
      "@typescript-eslint/no-explicit-any": "error",
      "@typescript-eslint/no-floating-promises": "error",
      "@typescript-eslint/consistent-type-imports": "error",
    },
  },
  { ignores: ["dist/**"] },
);

Rules Worth Knowing

RuleCatches
no-floating-promisessaveOrder() without await or .catch
no-misused-promisespassing an async function where a sync callback is expected
no-unnecessary-conditionchecks that are always true/false according to the types
no-explicit-any, no-unsafe-*any creeping into the codebase
switch-exhaustiveness-checkswitch over a union missing cases
consistent-type-importsuses import type for types