question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ESLint complains about unused variable when variable of it is used to define Typescript parameter type

See original GitHub issue

Tell us about your environment

  • ESLint Version: 6.8.0
  • Node Version: 12.16.3
  • npm Version: 6.14.5

What parser (default, Babel-ESLint, etc.) are you using? @typescript-eslint/parser Please show your full configuration:

Configuration
{
    "env": {
        "es6": true,
        "node": true
    },
    "extends": [
        "google"
    ],
    "globals": {
        "Atomics": "readonly",
        "SharedArrayBuffer": "readonly"
    },
    "parser": "@typescript-eslint/parser",
    "parserOptions": {
        "ecmaVersion": 2018,
        "sourceType": "module"
    },
    "plugins": [
        "@typescript-eslint"
    ],
    "rules": {
        "indent": [
            "error",
            4
        ],
        "require-jsdoc": 0
    }
}

What did you do? Please include the actual source code causing the issue, as well as the command that you used to run ESLint.

import * as Discord from 'discord.js';
export class CommandService {
    parseCommand(msg: Discord.Message) {
        // if (msg instanceof Discord.Message) console.log('');
    }
}

eslint "**/*.ts"

What did you expect to happen? Should have no error.

What actually happened? Please include the actual, raw output from ESLint. services/command.service.ts 1:13 error ‘Discord’ is defined but never used no-unused-vars

✖ 1 problem (1 error, 0 warnings)

Are you willing to submit a pull request to fix this bug? Don’t know how.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
anikethsahacommented, May 6, 2020

You need to extend typescript-eslint rules if you are using it for typescript. for no-unused-vars, use this rule and no-unused-vars-experimental.

0reactions
mdjermanoviccommented, May 8, 2020

The code you mentioned isn’t automatically generated when using eslint --init. So others may easily face this issue as well in the future.

This should be fixed with #13235

Read more comments on GitHub >

github_iconTop Results From Across the Web

ESLint warns about unused function parameter type
ESLint warns about unused function parameter type · 1. It's an issue with ESLint parsing the TS type. The rule itself is broken...
Read more >
no-unused-vars - ESLint - Pluggable JavaScript Linter
This rule is aimed at eliminating unused variables, functions, and function parameters. A variable foo is considered to be used if any of...
Read more >
no-unused-vars - TypeScript ESLint
Disallow unused variables. ... Examples​. This rule extends the base eslint/no-unused-vars rule. It adds support for TypeScript features, such as types.
Read more >
'X' is declared but its value is never read in TypeScript
To solve 'is declared but its value is never read' error in TypeScript, prefix any unused parameter name with an underscore, or disable...
Read more >
Improving code quality in Typescript with compiler options
This error is produced because we declared the digits variable without using it. You can get rid of this error by using the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found