ESLint with TS
ESLint catches bugs and style issues TypeScript itself doesn't — unused vars, missing await, accidental any. The typescript-eslint project adds type-aware rules on top.
Install
SHELL
pnpm add -D eslint typescript-eslint
Flat config (ESLint 9+)
eslint.config.js
import tseslint from 'typescript-eslint';
export default tseslint.config(
tseslint.configs.strict,
tseslint.configs.stylistic,
{
rules: {
'@typescript-eslint/no-unused-vars': ['error', { argsIgnorePattern: '^_' }],
'no-console': ['warn', { allow: ['warn', 'error'] }],
},
},
);
Type-aware rules
Some checks need actual type info — turn on the type-checked config:
eslint.config.js
import tseslint from 'typescript-eslint';
export default tseslint.config(
...tseslint.configs.recommendedTypeChecked,
{
languageOptions: {
parserOptions: {
projectService: true,
tsconfigRootDir: import.meta.dirname,
},
},
},
);
Useful TS-specific rules
| Rule | Catches |
|---|---|
no-floating-promises | Forgotten await on a Promise. |
no-misused-promises | Passing an async function where a callback is expected. |
strict-boolean-expressions | Truthy checks on non-bool values. |
no-unnecessary-condition | Condition is always true / false. |
no-explicit-any | Any explicit : any. |
consistent-type-imports | Force import type for type-only imports. |
Scripts
package.json
{
"scripts": {
"lint": "eslint .",
"lint:fix":"eslint . --fix"
}
}
Editor integration
Install the official ESLint extension in your editor. Most show errors inline and offer fix-on-save.
Tip: Don't pile rules on the team — start with
strict + stylistic + 5–10 hand-picked. Every rule has a cost in autofixes and arguments; ship the ones that catch real bugs.Example
Example
// pnpm add -D eslint typescript-eslint
// eslint.config.js (flat config, ESLint 9+):
// import tseslint from 'typescript-eslint';
// export default tseslint.config(
// tseslint.configs.strict,
// tseslint.configs.stylistic,
// );
console.log('ESLint + typescript-eslint = lint + type-aware rules');
Try it Yourself »
Exercise
NPM package that adds TS rules to ESLint.
Hyphenated; 17 characters.
Discussion
Loading…