Eslint によると、Typescript アプリのすべての列挙型は「すでに上位スコープで宣言されています」 質問する

Eslint によると、Typescript アプリのすべての列挙型は「すでに上位スコープで宣言されています」 質問する

新しいアプリケーションを起動して、eslint をインストールし、次の構成で構成しましたが、作成するたびに、enumすでに定義されていると表示されます。意味のない文字列であってもです。他の変数タイプ (const、var、let) ではこの問題は発生しません。ルールを無効にすることもできますが、実際に当てはまる状況に適用したいと思います。

    {
  "root": true,
  "parser": "@typescript-eslint/parser",
  "plugins": ["@typescript-eslint"],
  "parserOptions": {
    "project": ["./tsconfig.json"],
    "ecmaFeatures": {
      "ecmaVersion": 6,
      "jsx": true
    }
  },
  "overrides": [],
  "extends": [
    "airbnb-typescript",
    "prettier",
    "prettier/@typescript-eslint",
    "plugin:@typescript-eslint/recommended-requiring-type-checking"
  ],
  "rules": {
    "spaced-comment": 0,
    "import/prefer-default-export": 0,
    "@typescript-eslint/no-use-before-define": 0,
    "@typescript-eslint/restrict-template-expressions": [
      1,
      { "allowBoolean": true }
    ],
    "react/jsx-props-no-spreading": "off",
    "react/state-in-constructor": 0,
    "react/require-default-props": 0,
    "react/destructuring-assignment": [
      1,
      "always",
      {
        "ignoreClassFields": true
      }
    ]
  }
}

ここに画像の説明を入力してください

ベストアンサー1

TSLint-to-ESLintのユーザーであれば、これはその後修正されたバグ新しいバージョンでスクリプトを再実行すると問題も解決します。または、を無効にしてno-shadow有効にするだけでも解決します。@typescript-eslint/no-shadow

ルールを誤用しているパブリック設定を使用している場合は、必ずその旨を知らせてください。この問題に遭遇している人の数は、いまだに驚くほど多いです。


見る@typescript-eslint/no-shadow の使い方またFAQのこのセクション

使い方

module.exports = {
  "rules": {
    // Note: you must disable the base rule as it can report incorrect errors
    "no-shadow": "off",
    "@typescript-eslint/no-shadow": "warn"
  }
};

検索中typescript-eslint GitHub の問題同じことを質問している人が何人かいることを示しています。

おすすめ記事