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.

Bug: False positive no-unused-vars on import in custom.d.ts

See original GitHub issue

Tell us about your environment

Node version: v12.16.2 npm version: v6.13.6 Local ESLint version: v6.8.0 (Currently used) Global ESLint version: Not found OS: macOS 10.15.5

What parser (default, Babel-ESLint, etc.) are you using?

default

Please show your full configuration:

Configuration
module.exports = {
    'env': {
        'es6': true
    },
    'extends': 'eslint:recommended',
    'globals': {
        'process': true
    },
    'settings': {
        'import/resolver': {
            'node': {
                'extensions': ['.js', '.jsx', '.ts', '.tsx']
            }
        }
    },
    'parser': '@typescript-eslint/parser',
    'parserOptions': {
        'project': 'tsconfig.json',
        'sourceType': 'module'
    },
    'plugins': [
        '@typescript-eslint',
        'eslint-plugin-import'
    ],
    'rules': {
        '@typescript-eslint/indent': ['error', 4],
        '@typescript-eslint/no-require-imports': 'error',
        '@typescript-eslint/quotes': [
            'error',
            'single'
        ],
        'comma-dangle': 'error',
        'curly': 'error',
        'eqeqeq': [
            'error',
            'always'
        ],
        'no-trailing-spaces': 'error',
        'no-var': 'error',
        'prefer-const': 'error',
        'no-console': 'error',
        'no-unused-vars': ['error', { 'args': 'none' }],
        'no-throw-literal': 'error',
        'no-trailing-spaces': 'error',
        'import/no-extraneous-dependencies': 'error',
        'import/no-cycle': 'error',
        'import/no-self-import': 'error',
        'import/no-unresolved': 'error'
    },
    'overrides': [{
        'files': ['*.ts', '*.tsx'],
        'rules': {
            '@typescript-eslint/no-unused-vars': [2, { args: 'none' }],
            'no-undef': 'off'
        }
    }]
};

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

Contents of custom.d.ts file:

/* eslint-disable no-unused-vars */
import { Server } from 'ws';

declare global {
    namespace Express {
        interface Request {
            ws?: Server;
        }
    }
}

export {};
eslint -c .eslintrc.js --ext .ts src

What did you expect to happen?

I expected to be able to define the type of ws (imported from @types/ws)

What actually happened? Please include the actual, raw output from ESLint.

Two different failures:

  • the import is considered unused
  • eslint-disable no-unused-vars has no effect

Are you willing to submit a pull request to fix this bug?

I don’t have a fix to offer at this point.

Issue Analytics

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

github_iconTop GitHub Comments

3reactions
yeonjuancommented, Jun 4, 2020

@ajmas Hi 😃 some eslint rule does not work properly with typescript code. What about use typescript-eslint/no-unused-vars instead?

    'overrides': [{
        'files': ['*.ts', '*.tsx'],
        'rules': {
            'no-unused-vars': 'off', // off the eslint core rule.
            '@typescript-eslint/no-unused-vars': [2, { args: 'none' }],
            'no-undef': 'off'
        }
    }]

0reactions
ajmascommented, Jul 10, 2020

@mdjermanovic thanks. Will do.

Read more comments on GitHub >

github_iconTop Results From Across the Web

[@typescript-eslint/no-unused-vars] False positive no ... - GitHub
... False positive no-unused-vars on import in custom.d.ts #2287 ... Are you willing to submit a pull request to fix this bug?
Read more >
typescript-eslint/no-unused-vars false positive in type ...
And we have @typescript-eslint/no-unused-vars error in string with type declaration, which says 'name' is defined but never used.
Read more >
Importing into the United States A Guide for Commercial ...
This edition of Importing Into the United States contains material pursuant to the. Trade Act of 2002 and the Customs Modernization Act (Title...
Read more >
Working with Rules - ESLint - Pluggable JavaScript Linter
"problem" means the rule is identifying code that either will cause an error or may cause a confusing behavior. · "suggestion" means the...
Read more >
TypeScript - Fastify
npm init -y npm i fastify npm i -D typescript @types/node ... import { FromSchema } from "json-schema-to-ts"; fastify.post<{ Body: FromSchema<typeof todo> } ......
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