我打算将Prettier与ESLint一起用于TS。但这失败并显示错误
SyntaxError: Unexpected identifier, expected the token `)` (17:55)
与
一致const initialState = !process.env.IS_SERVER ? (window as any).__INITIAL_DATA__ : {};
此错误与更漂亮有关。
我已经安装了所有推荐的ES插件,以便与漂亮和TS一起使用。 此处的ES配置(.eslingrc.js):
module.exports = {
parser: "@typescript-eslint/parser", // Specifies the ESLint parser
extends: [
"plugin:react/recommended", // Uses the recommended rules from @eslint-plugin-react
"plugin:@typescript-eslint/recommended", // Uses the recommended rules from the @typescript-eslint/eslint-plugin
"prettier/@typescript-eslint", // Uses eslint-config-prettier to disable ESLint rules from @typescript-eslint/eslint-plugin that would conflict with prettier
"plugin:prettier/recommended" // Enables eslint-plugin-prettier and eslint-config-prettier. This will display prettier errors as ESLint errors. Make sure this is always the last configuration in the extends array.
],
parserOptions: {
ecmaVersion: 2018, // Allows for the parsing of modern ECMAScript features
sourceType: "module", // Allows for the use of imports
ecmaFeatures: {
jsx: true // Allows for the parsing of JSX
}
},
rules: {
// Place to specify ESLint rules. Can be used to overwrite rules specified from the extended configs
// e.g. "@typescript-eslint/explicit-function-return-type": "off",
},
settings: {
react: {
version: "detect" // Tells eslint-plugin-react to automatically detect the version of React to use
}
}
};
我使用IDE WebStorem。 对于类型的运算符扩展也无法使用prittier。
为什么不理解“作为”运算符? 请帮帮我。
答案 0 :(得分:0)
在 .eslintrc 中添加 parser 作为“typescript”。
rules: {
"prettier/prettier": ["error", {"singleQuote": true, "parser": "typescript", "endOfLine": "auto"}]
}
这为我修好了。
答案 1 :(得分:-1)
检查,prettier 文件配置扩展名 (.prettierrc.json)