Level Up Your TypeScript: A Developer's Guide to ESLint Integration
If you've ever found yourself in a TypeScript project where the code style feels a bit... loose, you're not alone. TypeScript handles your types, but it doesn't care about your formatting, unused variables, or questionable patterns. That's where linters come in, and for a long time, getting ESLint to play nicely with TypeScript was a bit of a hack.
Enter typescript-eslint. This toolchain is the officially supported way to plug ESLint into your TypeScript projects. It replaces the old, clunky tslint and bridges the gap seamlessly, letting you enforce code quality rules across your entire codebase with confidence.
What It Does
In short, typescript-eslint is a monorepo containing two key packages. The parser, @typescript-eslint/parser, allows ESLint to understand TypeScript syntax. The plugin, @typescript-eslint/eslint-plugin, provides a bundle of TypeScript-specific lint rules (like no-unused-vars that actually understands TypeScript types). Together, they let you run ESLint on .ts and .tsx files as if they were native JavaScript.
Why It's Cool
The beauty of this setup is its unification. You no longer need separate tools for JavaScript and TypeScript files in the same project. One ESLint configuration rules them all. It leverages TypeScript's own compiler, so the linting is type-aware—meaning it can catch errors that go beyond simple syntax and style.
The rule set is extensive and thoughtfully designed. You get rules to enforce best practices around type definitions, interface naming, and member ordering. It also provides ways to turn off ESLint's core rules that might conflict with TypeScript or are handled better by the TypeScript compiler itself, preventing those annoying false positives.
How to Try It
Getting started is straightforward. First, install the necessary packages in your TypeScript project:
npm install --save-dev eslint @typescript-eslint/parser @typescript-eslint/eslint-plugin
Next, create an ESLint configuration file (.eslintrc.js or .eslintrc.json) at your project root. A basic setup looks like this:
{ "root": true, "parser": "@typescript-eslint/parser", "plugins": ["@typescript-eslint"], "extends": [ "eslint:recommended", "plugin:@typescript-eslint/recommended" ]
}
Finally, add a script to your package.json to run the linter:
"scripts": { "lint": "eslint . --ext .ts,.tsx"
}
Run