我用——template typescript创建了一个新的React Native项目

我删除了作为样板的一部分的模板目录。

然后我继续添加ESLint:

module.exports = {
  parser: "@typescript-eslint/parser",
  plugins: ["@typescript-eslint"],
  extends: ["airbnb-typescript-prettier"]
};

然而,当我打开babel.config.js时,我得到这个错误

解析错误:"parserOptions. "已经为@typescript-eslint/parser设置了Project "。 该文件与您的项目配置不匹配:/Users/Dan/site/babel.config.js。 该文件必须包含在至少一个提供的项目中。eslint


当前回答

在".eslintignore"中添加一行:

.eslintrc.js

其他回答

您需要将该文件添加到tsconfig include数组中。 更多细节请参见typescript-eslint/typescript-eslint#967。

只需在.eslintrc.js文件中添加以下代码。

ignorePatterns: ['.eslintrc.js']

我在VsCode中有这个问题,当我在文件夹结构中打开我的项目太高时。一个奇怪的解决方案,但它有效。

在我的例子中,Firestore函数项目的express In .ts,我必须从它创建的函数文件夹中打开它。

我应该注意到这是这类问题,因为'npm run-script lint'本身从未返回错误。

Despite assurances that typescript definitely, absolutely, never caches anything, I suspected this was a caching issue after, when getting annoyed at incessant typescript errors while debugging and developing a feature, I modified my tsconfig.json to exclude my src directory temporarily. Upon reverting the change, and restarting my typescript server running through WebpackDevServer, I had this error, and got rid of it by doing yarn cache clean to clear my yarn cache, as well as rm -rf node_modules to delete my node modules folder. Then I re installed my packages with yarn and when I ran my devserver again, typescript/tslint no longer showed this error.

执行npm i -D @types/node 包括对*.config.js文件的typescript支持:

tsconfig.json:

{
  "include": [
    "**/*.config.js" // for *.config.js files
  ]
}

然后重新加载IDE!