首页 > 解决方案 > 预期的变量声明有一个 typedef

问题描述

我有这段代码显示警告:

const linkElement = getByText(/learn react/i);

预期的变量声明:'linkElement' 有一个 typedef (typedef)tslint(1)

getByText键入:(text: Matcher, options?: SelectorMatcherOptions | undefined, waitForElementOptions?: unknown) => HTMLElement

为什么我明确需要声明一个 typedef 给定 TS 知道linkElement是一个HTMLElement

我已将以下内容添加到我的.eslintrc但警告仍然存在:

"plugins": [
    "jsx-a11y",
    "prefer-arrow",
    "@typescript-eslint/tslint"
  ],
...
"rules": {
  "@typescript-eslint/typedef": [
      "off",
      {
        "variableDeclaration": false
      }
    ],
  "@typescript-eslint/no-inferrable-types": "error",

标签: typescripteslinttslint

解决方案


推荐阅读