Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

iTechGuides is reader-supported. When you buy through links on our site, we may earn an affiliate commission. As an Amazon Associate I earn from qualifying purchases. Learn more

To use @typescript-eslint/no-unused-vars, disable ESLint’s core no-unused-vars rule and enable the TypeScript-aware extension. To exempt underscore-prefixed names, add ^_ ignore patterns for each category your project wants to exempt; a variable pattern alone does not cover function arguments or other categories.

Enable the TypeScript-aware rule

@typescript-eslint/no-unused-vars extends ESLint’s core rule with support for TypeScript features, including types. The typescript-eslint documentation warns that the core rule can report incorrect errors on TypeScript, so turn it off when enabling the extension.

export default defineConfig({
  rules: {
    "no-unused-vars": "off",
    "@typescript-eslint/no-unused-vars": "error",
  },
});

The official documentation shows flat and legacy configuration forms. If your project extends plugin:@typescript-eslint/recommended, the rule is enabled by that preset. See the official no-unused-vars documentation for configuration details.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Exempt underscore-prefixed names by category

The rule’s ignore patterns are separate controls. For example, varsIgnorePattern applies to variables; it does not automatically exempt arguments, caught errors, or destructured array elements. Configure only the categories that match the convention you want.

This configuration follows the official example for emulating TypeScript’s underscore exemption:

{
  "@typescript-eslint/no-unused-vars": [
    "error",
    {
      "args": "all",
      "argsIgnorePattern": "^_",
      "caughtErrors": "all",
      "caughtErrorsIgnorePattern": "^_",
      "destructuredArrayIgnorePattern": "^_",
      "varsIgnorePattern": "^_",
      "ignoreRestSiblings": true
    }
  ]
}
  • varsIgnorePattern exempts matching variables.
  • argsIgnorePattern exempts matching function arguments. Setting args to all makes the rule check all arguments, so the pattern can exempt the intentionally unused ones.
  • caughtErrorsIgnorePattern exempts matching caught errors; caughtErrors: "all" makes all caught errors eligible for checking.
  • destructuredArrayIgnorePattern exempts matching names in array destructuring.
  • ignoreRestSiblings: true ignores unused siblings when using rest properties in object destructuring.

The pattern ^_ matches names beginning with an underscore. If you want underscore exemptions only for some kinds of names, omit the other category settings rather than assuming one pattern governs them all.

Rank #2
TypeScript Programming Language - Software Engineer & Coder T-Shirt
  • TypeScript implements a superset of syntax for strictly typed development, facilitating deep static analysis and enhanced development environment integration. The compiler translates source into standard script formats, ensuring parity across any runtime.
  • TypeScript is ideal for front-end developers, full-stack engineers, and software architects who build large-scale web applications. It serves those looking to improve code excellence, reduce bugs through static checking, and maintain complex projects more.
  • Lightweight, Classic fit, Double-needle sleeve and bottom hem

Choose between ESLint and TypeScript compiler checks

TypeScript’s noUnusedLocals and noUnusedParameters compiler options can report unused locals and parameters. typescript-eslint recommends its lint rule for these checks because it offers more configurable exemptions and can be scoped through ESLint configuration at line, file, or folder level; compiler options are tied to a TSConfig. Compiler diagnostics may also block builds more directly than lint findings, depending on how the project runs its checks.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Disabling those compiler options does not necessarily remove editor indicators: editors such as VS Code may still grey out unused variables.

Decide whether unused imports should be removed automatically

The TypeScript-specific enableAutofixRemoval.imports option defaults to false. With the default, unused imports receive suggestion fixes rather than automatic fixes. Setting it to true allows automatic removal; if every imported specifier is unused, the whole import declaration is removed.

Keep automatic import removal disabled if your codebase relies on side effects from imports. Removing an apparently unused import can otherwise change runtime behavior.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Why can the rule report code that looks used?

A value appears only in a type position

A variable used only in a type position does not count as used by this rule. The documentation illustrates this with typeof and a Zod schema. If a runtime value exists only to produce a type, consider whether a direct type declaration better expresses the intent.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

A name appears in a JSDoc link

JSDoc @link references are not recognized as uses by this rule. The typescript-eslint documentation points to a separate JSDoc rule as one possible way to address undefined references.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.