首页 > 解决方案 > Typescript 在枚举中报告未使用的变量

问题描述

在我的 React 项目中,我得到了以下代码: export enum Tab {BASIC = 'BASIC', ADVANCED = 'ADVANCED', SETTINGS = 'SETTINGS'}

每个枚举案例都给我一个警告,它们已分配但从未使用过。

我已经看到了一些解决方案,但它们似乎不起作用。首先是我的 tsconfig 和 eslintrc。你可以看到我有parser: '@typescript-eslint/parser'。同样在我的 package.json:"eslint-plugin-typescript": "^1.0.0-rc.3"和 devDependencies 中:"@typescript-eslint/eslint-plugin": "^2.7.0", "@typescript-eslint/parser": "^2.7.0",

tsconfig

{
  "compilerOptions": {
    "target": "es5",
    "lib": [
      "dom",
      "dom.iterable",
      "esnext"
    ],
    "allowJs": true,
    "skipLibCheck": true,
    "esModuleInterop": true,
    "allowSyntheticDefaultImports": true,
    "strict": true,
    "noImplicitAny": false,
    "forceConsistentCasingInFileNames": true,
    "module": "esnext",
    "moduleResolution": "node",
    "resolveJsonModule": true,
    "isolatedModules": true,
    "noEmit": true,
    "jsx": "react"
  },
  "include": [
    "src"
  ]
}

eslintrc.js

module.exports = {
    env: {
        browser: true,
        es6: true,
    },
    extends: [
        'react-app',
    ],
    globals: {
        Atomics: 'readonly',
        SharedArrayBuffer: 'readonly',
    },
    parser: '@typescript-eslint/parser',
    parserOptions: {
        ecmaFeatures: {
            jsx: true,
        },
        ecmaVersion: 2018,
        sourceType: 'module',
    },
    plugins: [
        'react',
        '@typescript-eslint',
    ],
    rules: {},
};

我也尝试在 eslintrc 中添加'@typescript-eslint'extends但它说failed to load @typescript-eslint to extend from

我怎样才能解决这个问题?

标签: reactjstypescript

解决方案


推荐阅读