it-source

유형 선언의 @typescript-eslint/no-discript-false positive false 긍정

criticalcode 2023. 2. 22. 22:16
반응형

유형 선언의 @typescript-eslint/no-discript-false positive false 긍정

@typescript-eslint/no-unused-vars에는 1가지 문제가 있습니다.그래서 우리는 타입이 있다.

type SomeType = (name: string) => void;

또한 유형 선언 문자열에 @typescript-eslint/no-unused-vars 오류가 있습니다. 문자열은 'name'은 정의되어 있지만 사용되지 않습니다.

유형 사용 예:

export const LogSomeInfo: SomeType = (name: string) => {
    const a = name;
    console.log(a);
};

또는 다음 중 하나를 선택합니다.

interface CheckboxPropsType {
    value: string,
    onClick(value: string): void
}

그리고 onClick에서 eslint 브레이크...값은 정의되지만 사용되지 않음을 나타내는 문자열입니다.유형이 올바르게 할당되어 실제 onClick 핸들러가 값을 사용하더라도!

질문:.이 규칙의 문제점과 이 경우 트리거되는 이유eslint는 유형/인터페이스의 함수에 대한 유형 선언을 일반 함수로 인식하는 이유는 무엇입니까?내 eslint 구성에 문제가 있다고?

"eslint": "^7.7.0", "@typescript-eslint/eslint-parser": "^3.6.1", "@typescript-eslint/parser": "^4.0.1", "eslint-config-slint-parcript": "^9.0.0",

{
  "extends": [
    "airbnb-typescript",
    "airbnb/hooks",
    "plugin:react/recommended",
    "plugin:@typescript-eslint/recommended"
  ],
  "parser": "@typescript-eslint/parser",
  "parserOptions": {
    "ecmaFeatures": {
      "jsx": true
    },
    "ecmaVersion": 2018,
    "sourceType": "module",
    "project": "./tsconfig.json"
  },
  "settings": {
    "react": {
      "version": "detect"
    }
  },
  "plugins": ["@typescript-eslint", "react-hooks", "react"],
  "env": {
    "browser": true
  },
  "rules": {
    "object-curly-newline": 0,
    "import/named": ["error"],
    "indent": ["error", 4],
    "react/jsx-indent": ["error", 4],
    "comma-dangle": ["error", "never"],
    "import/prefer-default-export": "off",
    "react/jsx-fragments": "off",
    "arrow-body-style": "off",
    "object-curly-spacing": "off",
    "@typescript-eslint/indent": ["error", 4, {"SwitchCase": 1}],
    "@typescript-eslint/explicit-module-boundary-types": "off",
    "no-undef": "error",
    "react/jsx-indent-props": ["error", 4],
    "max-len": ["error", { "code": 120 }],
    "react/prop-types": "off"
  }
}

출처: 저는 이 회사의 관리자입니다.typescript-eslint프로젝트.

버전을 갱신하는 경우@typescript-eslint/parser그리고.@typescript-eslint/eslint-pluginv4.1.0에서는, 다음의 최신의 변경을 사용할 수 있습니다.@typescript-eslint/no-unused-vars모든 경우에 적절하게 작용합니다.


참고로 플러그인의 v3.x를 사용하지만 파서의 v4.x를 사용하면 정의되지 않은 동작과 지원되지 않는 동작이 있는 매우 이상한 상태가 됩니다.

각 버전이 함께 출시되므로 두 패키지의 버전이 항상 동일한지 확인해야 합니다.

이전에도 비슷한 질문을 했습니다.ESLint가 TypeScript 인터페이스에 대해 'no-unused-vars'를 슬로우하는 이유는 무엇입니까?

무효화'@typescript-eslint/no-unused-vars': 0규칙 대신 사용"strict": true,"noUnusedLocals": true,그리고."noUnusedParameters": true, tsconfig.json에서

다음의 최신 버전이 있는 것을 확인해 주세요.

  • 타이프 스크립트
  • @typescript-eslint/parser
  • @typescript-eslint/eslint-module

.eslintrc.displays에서 규칙 섹션에 다음 행이 추가되어 있는지 확인합니다.

  "no-unused-vars": "off",
  "@typescript-eslint/no-unused-vars": ["error"]

이 문제를 해결하기 위한 또 다른 옵션은typescript-eslint고객님께extends제거하다plugins:

extends: [
  `plugin:@typescript-eslint/recommended',
]

그런 다음 이 파일을 제거할 수도 있습니다.parser: @typescript-eslint/parser확장하면 플러그인이 이 모든 것을 처리할 수 있기 때문입니다.필요에 따라서, 몇개의 룰을 덮어쓸 수 있습니다.

  rules: {
    '@typescript-eslint/no-unused-vars': ['off'],
  },

언급URL : https://stackoverflow.com/questions/63767199/typescript-eslint-no-unused-vars-false-positive-in-type-declarations

반응형