Sub topic 4
Choosing a preset: recommended, strict and stylistic
This chapter assumes you already have a working eslint.config.mjs that loads typescript-eslint, as covered in the earlier chapters. It also assumes you can read a tsconfig.json and know the difference between a lint error and a compiler error.
A preset is a ready-made bundle of rules. typescript-eslint ships several, and picking one is the largest single decision in your lint setup. This chapter explains what each preset contains, how they combine, and how to choose.
The preset family
typescript-eslint exposes its presets as properties of tseslint.configs. There are three levels of strictness, and each comes in two variants: one that needs type information and one that does not.
| Preset | Purpose | Needs type information |
|---|---|---|
| `recommended` | Rules that catch likely bugs with few false positives | No |
| `recommendedTypeChecked` | `recommended` plus bug-catching rules that read types | Yes |
| `strict` | `recommended` plus more opinionated bug-catching rules | No |
| `strictTypeChecked` | `strict` plus type-aware rules | Yes |
| `stylistic` | Consistency rules about how code is written | No |
| `stylisticTypeChecked` | `stylistic` plus type-aware style rules | Yes |
Two further families exist: the -type-checked-only presets (for example recommendedTypeChecked without the non-type rules) and all. The -only presets are meant for combining with a non-type-checked preset yourself. The all preset enables every rule, including rules that conflict with each other, and the maintainers do not recommend it for real projects.
What each level means
recommended
recommended is the default choice. It holds rules that flag code that is almost certainly wrong or unsafe. Examples include:
@typescript-eslint/no-explicit-any, which reports uses of theanytype.@typescript-eslint/no-unused-vars, a TypeScript-aware replacement for the core rule.@typescript-eslint/ban-ts-comment, which restricts// @ts-ignorestyle comments.@typescript-eslint/no-namespaceand@typescript-eslint/no-empty-object-type.
The project keeps this preset stable. Its contents change only in major releases, so upgrading a minor version will not suddenly produce new errors in your codebase.
strict
strict includes everything in recommended and adds rules that catch more problems but are more opinionated. Some teams will disagree with them. Examples include:
@typescript-eslint/no-non-null-assertion, which reportsvalue!.@typescript-eslint/no-extraneous-class, which reports classes that only hold static members or nothing at all.@typescript-eslint/unified-signatures, which reports overloads that could be a single signature.
Unlike recommended, strict can gain rules in minor releases. If you use it, expect an occasional new report after an upgrade, and pin versions or upgrade on a schedule.
stylistic
stylistic is a different kind of preset. It does not look for bugs. It enforces one consistent way of writing equivalent code. Examples include:
@typescript-eslint/consistent-type-definitions, which prefersinterfaceover an object-shapedtypealias.@typescript-eslint/array-type, which prefersstring[]overArray<string>.@typescript-eslint/no-inferrable-types, which reportsconst n: number = 5.@typescript-eslint/prefer-for-of, which reports index loops that only read elements.
Unlike strict, stylistic does not include recommended. The two are independent, so you usually combine them.
Seeing the difference in code
The following file is clean under recommended but produces reports under strict and stylistic. The comments name the rule that fires.
// Reported by stylistic: consistent-type-definitions
type Point = { x: number; y: number };
// Reported by stylistic: array-type
export const names: Array<string> = ['a', 'b'];
// Reported by stylistic: no-inferrable-types
export const count: number = 3;
export function firstChar(input: string | undefined): string {
// Reported by strict: no-non-null-assertion
return input!.charAt(0);
}
export function describe(p: Point): string {
return `${p.x},${p.y}`;
}The input! assertion is a good example of why strict exists. It tells the compiler to trust you, and if input is undefined at runtime the code throws. recommended leaves that choice to you. strict asks you to handle the case instead.
Combining presets in a config
Presets are ordinary config objects, so you list them in order inside defineConfig. Later entries override earlier ones for the same rule, so put presets first and your own rule changes last.
// 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.strict,
tseslint.configs.stylistic,
);Because strict already contains recommended, listing both would be redundant but harmless. Do not list strict and strictTypeChecked together. The second already contains the first's rules, and two overlapping presets make the config harder to read.
Choosing the type-checked variants
The type-checked presets add rules that use the TypeScript compiler's type information. Examples are no-floating-promises, no-unsafe-assignment, await-thenable and, in strictTypeChecked, no-unnecessary-condition. These rules find bugs that syntax alone cannot show. For instance, no-floating-promises has to know that a function returns a Promise.
The cost is that ESLint must build a TypeScript program for your files. A type-checked preset therefore requires the project service to be configured, and it makes linting slower. Later chapters cover that setup and its cost. For now, note the rule of thumb:
- If you have not set up type-aware linting, use the plain presets.
- If you have, prefer the type-checked variant of whichever level you chose. The plain presets leave real bugs unchecked.
The following config uses the strictest combination. It is the setup the typescript-eslint documentation suggests for projects that want maximum coverage.
// 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.strictTypeChecked,
tseslint.configs.stylisticTypeChecked,
{
languageOptions: {
parserOptions: {
projectService: true,
tsconfigRootDir: import.meta.dirname,
},
},
},
);A rule that only exists in strictTypeChecked shows the effect. With strictNullChecks on, the optional chain below is unnecessary, and no-unnecessary-condition reports it.
interface User {
name: string;
}
export function greet(user: User): string {
return `Hello, ${user?.name}`; // reported: user is never nullish
}Common errors when choosing presets
- Adding a type-checked preset without
projectService. ESLint fails with an error saying a rule requires type information. The fix is to add the parser options, not to switch presets. - Type-checked rules running on plain JavaScript files. Config files such as
eslint.config.mjsare usually not in yourtsconfig.json, so rules that need types fail on them. Applytseslint.configs.disableTypeCheckedto those files, as shown in the file-scoped overrides chapter. - Expecting
stylisticto catch bugs. It will not. A project that only enablesstylistichas no protection againstanyor floating promises. - Starting at
stricton an old codebase. The first run may produce hundreds of reports, and the team will learn to ignore the output. - Duplicating rules by hand. If you copy individual rules from a preset into your config, you lose automatic updates. Extend the preset and override only what you disagree with.
A practical decision process
- Start with
recommended, orrecommendedTypeCheckedif you can afford type-aware linting. - Fix or consciously disable what it reports, so the lint run is clean.
- Add
stylisticif your team wants the style rules enforced by tooling rather than review comments. - Move to
strictonce the codebase is clean and the team accepts the opinionated rules. Do it as its own change so new reports are easy to review. - Adjust individual rules, as covered in the next chapter, instead of dropping a whole preset because one rule is unwelcome.
Exercise
A team uses tseslint.configs.strict and notices that const n: number = 5 is not reported. Why, and what is the smallest config change that reports it?
Show answer
The rule that reports it, no-inferrable-types, belongs to the stylistic preset, and strict does not include stylistic. Add tseslint.configs.stylistic to the defineConfig list after strict.
Exercise
You enable tseslint.configs.recommendedTypeChecked and ESLint reports that it needs type information for eslint.config.mjs itself. What are two ways to resolve this?
Show answer
Apply tseslint.configs.disableTypeChecked to the JavaScript config files through a files entry, or include those files in a tsconfig that the project service can find. The first is the usual choice because config files rarely belong in the TypeScript project.
Exercise
Why might a team choose recommended over strict for a ten-year-old codebase, even if they like the strict rules?
Show answer
strict adds more opinionated rules, so a first run on old code produces many reports. Starting with recommended gives a clean baseline, and the team can adopt strict later as a separate, reviewable change. Because strict can also gain rules in minor releases, it needs a deliberate upgrade routine.