typescript-eslint
Original:🇺🇸 English
Translated
typescript-eslint - ESLint plugin for TypeScript USE WHEN: user mentions "typescript-eslint", "TypeScript linting", "type-aware rules", asks about "no-floating-promises", "TypeScript ESLint config", "@typescript-eslint rules" DO NOT USE FOR: ESLint 9 full setup - use `eslint-biome` skill, Biome - use `eslint-biome`, general quality - use `quality-common`
2installs
Added on
NPX Install
npx skill4agent add claude-dev-suite/claude-dev-suite typescript-eslintTags
Translated version includes tags in frontmatterSKILL.md Content
View Translation Comparison →typescript-eslint - Quick Reference
When to Use This Skill
- Configure ESLint for TypeScript projects
- Type-aware rules for TypeScript
- Migration from TSLint
When NOT to Use This Skill
- Full ESLint 9 setup - Use skill for complete configuration
eslint-biome - Biome linter - Use skill for Biome setup
eslint-biome - Code quality principles - Use for SOLID/Clean Code
quality-common - Java/Kotlin - Use skill for JVM languages
sonarqube
Deep Knowledge: Usewith technology:mcp__documentation__fetch_docsfor comprehensive documentation.typescript-eslint
Basic Setup
bash
npm install -D eslint typescript-eslintFlat Config (ESLint 9+)
eslint.config.mjs
javascript
import eslint from '@eslint/js';
import tseslint from 'typescript-eslint';
export default tseslint.config(
eslint.configs.recommended,
...tseslint.configs.recommended,
);Type-Aware Linting
javascript
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,
},
},
},
);Strict Configuration
javascript
export default tseslint.config(
eslint.configs.recommended,
...tseslint.configs.strictTypeChecked,
...tseslint.configs.stylisticTypeChecked,
);Common Rules
javascript
{
rules: {
// Prevent unused variables
'@typescript-eslint/no-unused-vars': ['error', {
argsIgnorePattern: '^_'
}],
// Require explicit return types
'@typescript-eslint/explicit-function-return-type': 'warn',
// Prevent any usage
'@typescript-eslint/no-explicit-any': 'error',
// Require await in async functions
'@typescript-eslint/require-await': 'error',
// Prevent floating promises
'@typescript-eslint/no-floating-promises': 'error',
// Consistent type imports
'@typescript-eslint/consistent-type-imports': 'error',
}
}File-Specific Rules
javascript
export default tseslint.config(
// ... base config
{
files: ['**/*.test.ts', '**/*.spec.ts'],
rules: {
'@typescript-eslint/no-explicit-any': 'off',
},
},
{
files: ['**/*.js'],
...tseslint.configs.disableTypeChecked,
},
);Anti-Patterns
| Anti-Pattern | Why It's Bad | Correct Approach |
|---|---|---|
| Not using type-aware rules | Misses Promise, async issues | Use |
Allowing | Defeats TypeScript purpose | Set |
No | Unnecessary async keywords | Enable type-aware async rules |
| Type checking JS files | JS has no types | Use |
| Disabling rules in test files | Tests need quality too | Only disable |
| Ignoring unused variables | Code smell, unused imports | Use |
Quick Troubleshooting
| Issue | Likely Cause | Solution |
|---|---|---|
| Type-aware rules not working | Missing | Add to languageOptions.parserOptions |
| Linting very slow | Type checking all files | Limit type rules to |
| "Unsafe" errors everywhere | Strict type checking | Use |
| Promise errors not caught | Missing | Enable in recommendedTypeChecked preset |
| Unused imports not detected | Wrong rule configuration | Use |
| Rules conflict with Prettier | Both formatting code | Add |