Getting Started
TypeScript
Getting started using ESLint React in your TypeScript React project
This instruction requires the following minimum versions:
- Node.js: 18.18.0
- ESLint: 8.57.0
- TypeScript: 4.9.5
Installation
npm install --save-dev typescript-eslint @eslint-react/eslint-plugin
pnpm add --save-dev typescript-eslint @eslint-react/eslint-plugin
yarn add --dev typescript-eslint @eslint-react/eslint-plugin
bun add --dev typescript-eslint @eslint-react/eslint-plugin
Configure ESLint
// @ts-check
import eslintJs from "@eslint/js";
import eslintReact from "@eslint-react/eslint-plugin";
import tseslint from "typescript-eslint";
export default tseslint.config({
files: ["**/*.ts", "**/*.tsx"],
// Extend recommended rule sets from:
// 1. ESLint JS's recommended rules
// 2. TypeScript ESLint recommended rules
// 3. ESLint React's recommended-typescript rules
extends: [
eslintJs.configs.recommended,
tseslint.configs.recommended,
eslintReact.configs["recommended-typescript"],
],
// Configure language/parsing options
languageOptions: {
// Use TypeScript ESLint parser for TypeScript files
parser: tseslint.parser,
parserOptions: {
// Enable project service for better TypeScript integration
projectService: true,
tsconfigRootDir: import.meta.dirname,
},
},
// Custom rule overrides (modify rule levels or disable rules)
rules: {
"@eslint-react/no-missing-key": "warn",
},
});
Configure Language Config (Optional)
// @ts-check
import tseslint from "typescript-eslint";
export default [
{
languageOptions: {
parser: tseslint.parser,
parserOptions: {
projectService: true,
tsconfigRootDir: import.meta.dirname,
},
},
},
];
{
"compilerOptions": {
// ...other options
"jsx": "react-jsx"
},
"include": ["**/*.ts", "**/*.tsx"]
}
TIP
Once you've correctly configured the language service integration for the files to be linted, ESLint React utilizes the information from the TypeScript compiler to provide better linting results.
For more information, see the Configure Language Config section.