简体   繁体   中英

Eslint typescript no-unused-vars triggers for imported type

I can't figure out why this doesn't work. I would expect @typescript-eslint/no-unused-vars to recognize the type as being used for this function return type. What am I doing wrong? Am I miss-understanding how this is supposed to work?

在此处输入图像描述

Code from the image:

.eslintrc.json

{
    "env": {
        "browser": false,
        "node": true
    },
    "extends": [
        "airbnb-base",
        "eslint:recommended",
        "plugin:@typescript-eslint/eslint-recommended"
    ],
    "parser": "@typescript-eslint/parser",
    "parserOptions": {
        "ecmaVersion": 2020,
        "sourceType": "module"
    },
    "plugins": [
        "typescript",
        "@typescript-eslint"
    ],
    "settings": {
        "import/resolver": {
            "typescript": {}
        }
    },
    "rules": {
        "no-unused-vars": "off",
        "@typescript-eslint/no-unused-vars": ["error"]
    }
}

Service.ts:

export declare interface FooConfig {}

Foo.ts:

import { FooConfig } from "library/types/Service";

export default function foo(): FooConfig {

    return {};

}

Error:

ESLint: 'FooConfig' is defined but never used. (@typescript-eslint/no-unused-vars)

Looks like this is a known issue for the version I'm using (4.0.0-alpha.1) and will hopefully be fixed soon.

https://github.com/typescript-eslint/typescript-eslint/issues/2337

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM