我已在我的eslintrc
配置中为数组禁用逗号悬挂,如下所示:
{
"parser": "@typescript-eslint/parser",
"extends": ["airbnb-typescript", "plugin:@typescript-eslint/recommended"],
"rules": {
"react/jsx-filename-extension": "off",
"import/newline-after-import": ["error", { "count": 1 }],
"lines-between-class-members": "error",
"newline-before-return": "error",
"quotes": ["error", "single"],
// here
"comma-dangle": [
"error",
{
"arrays": "never",
"objects": "always",
"imports": "never",
"exports": "never",
"functions": "never"
}
],
"react/prop-types": "off"
},
"ignorePatterns": ["config", "public", "scripts"]
}
这是我的数组:const foo = [1, 2, 3];
VS代码不会突出显示任何错误以将尾随逗号添加到foo
的最后一个元素,而Typescript无法编译并出现以下错误:缺少尾随逗号-悬挂。由于某些原因,打字稿无法遵循我的.eslintrc
配置中编写的规则。
tsconfig :
{
"compilerOptions": {
"target": "es5",
"lib": ["dom", "dom.iterable", "esnext"],
"allowJs": true,
"skipLibCheck": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"module": "esnext",
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"noEmit": true,
"jsx": "react"
},
"include": ["src"]
}
已创建create-react-app
打字稿模板项目。你能指导我这里做错了什么吗?谢谢:)