Sub topic 4
Choosing a typescript-eslint Preset
Assume you know TypeScript syntax, have a tsconfig.json, and can run npm commands. This chapter focuses on choosing rules with typescript-eslint, not on installing ESLint or explaining every rule.
A preset is a ready-made group of ESLint rules. The preset determines which problems ESLint reports and how strict those reports are. You can combine a preset with your own rule settings.
The three main presets
The presets form a practical progression:
- Recommended catches likely mistakes and unsafe patterns with relatively low noise.
- Strict adds rules that enforce stronger TypeScript practices. Some rules require more decisions from your team.
- Stylistic focuses on consistent code style, such as naming, spacing, and syntax choices.
The presets are separate concerns. A project can use recommended rules for correctness and a formatter for layout. It can also add stylistic rules when the team wants ESLint to enforce particular coding conventions.
| Preset | Main purpose | Good starting point |
|---|---|---|
| `recommended` | Common errors and unsafe patterns | Most projects |
| `strict` | Stronger TypeScript correctness and design guidance | New or tightly controlled projects |
| `stylistic` | Consistent TypeScript syntax and style | Projects without another style tool |
strict may introduce rules or behavior that changes between versions. Review its changes when upgrading typescript-eslint. Recommended presets are usually the safer default for an existing codebase.
Type-checked variants
The ordinary presets analyze source code and syntax. Their type-checked variants also use information from the TypeScript program.
For example, a syntax-only rule can see that a function call exists. A type-checked rule can determine that the call returns a Promise that the code does not await.
The corresponding type-checked presets are:
recommendedTypeCheckedstrictTypeCheckedstylisticTypeChecked
Type-checked linting can find deeper problems, but ESLint must load TypeScript project information. That makes linting slower and requires configuration through the project service.
// eslint.config.mjs
import eslint from '@eslint/js';
import tseslint from 'typescript-eslint';
import { defineConfig } from 'eslint/config';
export default defineConfig(
eslint.configs.recommended,
tseslint.configs.recommendedTypeChecked,
{
languageOptions: {
parserOptions: {
projectService: true,
tsconfigRootDir: import.meta.dirname,
},
},
},
);The diagram shows the usual selection path.
Combining and adjusting presets
A preset is a starting point, not a permanent decision. You can include more than one preset, then adjust individual rules.
// eslint.config.mjs
import tseslint from 'typescript-eslint';
import { defineConfig } from 'eslint/config';
export default defineConfig(
tseslint.configs.recommended,
tseslint.configs.stylistic,
{
rules: {
'@typescript-eslint/consistent-type-imports': 'warn',
'@typescript-eslint/no-explicit-any': 'error',
},
},
);Avoid enabling every preset automatically. Overlapping rules can create noise, and developers may stop trusting lint results. Start with recommended, measure the violations, then add strict or stylistic rules that support a clear team decision.
Exercise
Which preset should you choose for a project that wants common bug checks but already uses a separate formatter?
Show answer
Start with tseslint.configs.recommended. Add recommendedTypeChecked if the team accepts the extra setup and linting time.