Add type-aware lint rules with typescript-eslint
Turn on type-aware lint rules such as no-floating-promises with typescript-eslint and projectService, and see the rules that need it.
Rules that need to know a value's type, such as "this promise is never awaited", cannot work from syntax. typescript-eslint can ask the TypeScript compiler, if you tell it where your project is.
import eslint from '@eslint/js';
import tseslint from 'typescript-eslint';
export default tseslint.config(
eslint.configs.recommended,
tseslint.configs.recommendedTypeChecked,
{
languageOptions: {
parserOptions: {
projectService: true,
tsconfigRootDir: import.meta.dirname,
},
},
},
);async function save() {}
save(); // flagged by @typescript-eslint/no-floating-promisessrc/job.ts
2:1 error Promises must be awaited, end with a call to .catch, or end with a call to .then with a rejection handler @typescript-eslint/no-floating-promisesrecommendedTypeChecked adds rules such as no-floating-promises, no-misused-promises and await-thenable. projectService: true finds the nearest tsconfig.json for each file, which replaced the older project setting. Linting is slower, because TypeScript builds the type graph. See typescript-eslint typed linting.
Files that are not in a tsconfig, such as eslint.config.js, cause a parsing error. Turn the type-aware rules off for them with tseslint.configs.disableTypeChecked in a files block.