DEV Community

Antonov Mike
Antonov Mike

Posted on

TypeScript warnings

I really don't like the way JavaScript / TypeScript works with unused variables.

Unused variables are not underlined

I guess unused variables, constants and imports should be underlined by default.

Unused variables are underlined

I mean by default, so you don't have to configure it manually:

package.json

{
  "type": "module",
  "devDependencies": {
    "@types/node": "^25.5.2",
    "@typescript-eslint/eslint-plugin": "^8.58.0",
    "@typescript-eslint/parser": "^8.58.0"
  }
}
Enter fullscreen mode Exit fullscreen mode

eslint.config.js

export default [
  {
    files: ["**/*.ts"],
    languageOptions: { ecmaVersion: 2021, sourceType: "module" },
    rules: {
      "no-unused-vars": [
        "warn",
        { vars: "all", args: "after-used", ignoreRestSiblings: true },
      ],
    },
  },
];

Enter fullscreen mode Exit fullscreen mode

{Updated on 2026.04.04}

Rules for frontend (React TypeScript)

eslint.config.js

import js from "@eslint/js";
import globals from "globals";
import reactHooks from "eslint-plugin-react-hooks";
import reactRefresh from "eslint-plugin-react-refresh";
import tseslint from "typescript-eslint";
import { defineConfig, globalIgnores } from "eslint/config";

export default defineConfig([
  globalIgnores(["dist"]),
  {
    files: ["**/*.{ts,tsx}"],
    extends: [
      js.configs.recommended,
      tseslint.configs.recommended,
      reactHooks.configs.flat.recommended,
      reactRefresh.configs.vite,
    ],
    languageOptions: {
      ecmaVersion: 2020,
      globals: globals.browser,
    },
    rules: {

      // Disable the TS version (if it sets an error)

      "@typescript-eslint/no-unused-vars": "off",

      // Enable the base rule as a warning.

      "no-unused-vars": [
        "warn",
        { vars: "all", args: "after-used", ignoreRestSiblings: true },
      ],
      "prefer-const": ["warn"],
    },
  },
]);
Enter fullscreen mode Exit fullscreen mode

Top comments (3)

Collapse
 
ddebajyati profile image
Debajyati Dey

well I use neovim and by deafult settings of the LSP - I don't get underlines but what I get is also useful.

I know the below example is of a python file, but this is what kind of messages it shows also in case of js/ts files -
LSP diagnostics - unused var

Collapse
 
antonov_mike profile image
Antonov Mike

Thanks for sharing. Personally, I find underlining more convenient than dimmed text. Yellow = warning. Red = error.

Collapse
 
ddebajyati profile image
Debajyati Dey

that's nice to know. I would try to get that working in my editor and see.