Careeroza
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
| Rule | Catches |
|---|---|
no-floating-promises | saveOrder() without await or .catch |
no-misused-promises | passing an async function where a sync callback is expected |
no-unnecessary-condition | checks that are always true/false according to the types |
no-explicit-any, no-unsafe-* | any creeping into the codebase |
switch-exhaustiveness-check | switch over a union missing cases |
consistent-type-imports | uses import type for types |