我用——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
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.
我碰巧有同样的问题一段时间,然后在添加.html到我的tsconfig的包含数组。Json文件,问题已被修复。
因为我在做一个Angular项目,所以在overrides中的files数组中,你可能会看到我的components扩展名,你可能需要根据项目的需要进行更改。
在eslintrc。Json文件,你需要有以下配置:
"extends": [
"plugin:@typescript-eslint/eslint-recommended",
"plugin:@typescript-eslint/recommended",
"plugin:@typescript-eslint/recommended-requiring-type-checking",
"plugin:@angular-eslint/recommended"
],
"overrides": [
{
"files": ["*.ts", "*.component.html", "*.component.ts"],
"parserOptions": {
"project": ["./tsconfig.json"],
"extraFileExtensions": [".html"]
},
"rules": { "@typescript-eslint/prefer-nullish-coalescing": "error" }
}
],
"parser": "@typescript-eslint/parser",
确保在tsconfig中有以下行。json文件:
"include": ["**/*.d.ts", "**/*.ts", "**/*.html", "**/*.scss", "**/*.css"],