[英]Eslint+prettier do not know keyof typeof
my eslint is calling out an error on my TS code which should work:我的 eslint 在我的 TS 代码上调用了一个错误,它应该可以工作:
const foo = {
key1: 'value1',
key2: 'value2'
};
type MyType = keyof typeof foo;
ESLint: Parsing error: Unexpected token `typeof`, expected the token `;`(prettier/prettier
App is created by create-react-app
tool with some default config for eslint and I added prettier support, here is my config of all of that:应用程序是由
create-react-app
工具创建的,带有一些用于 eslint 的默认配置,我添加了更漂亮的支持,这是我的所有配置:
// eslintrc
"extends": [
"react-app",
"react-app/jest",
"eslint:recommended",
"plugin:prettier/recommended"
],
here is printscreen of my IDE with the error这是我的 IDE 的打印屏幕,出现错误
Any ideas?有任何想法吗? Thanks!
谢谢!
Edit1 : actually I have found out that plugin:prettier/recommended
is causing it and when I remove it will stop calling out that error. Edit1 :实际上我发现
plugin:prettier/recommended
是导致它的原因,当我删除它时,它将停止调用该错误。 However I would like to have this plugin added但是我想添加这个插件
make sure you use a compatible parser to eslintrc.js, try these settings:确保您使用兼容的解析器来 eslintrc.js,尝试以下设置:
module.exports = {
root: true,
parser: '@typescript-eslint/parser',
plugins: ['@typescript-eslint'],
extends: [
"react-app",
"react-app/jest",
"plugin:prettier/recommended",
"prettier/@typescript-eslint",
"prettier/react"
]
};
Still experiencing the issue even with this look of my config:即使我的配置看起来像这样,仍然遇到问题:
{
"root": true,
"parser": "@typescript-eslint/parser",
"extends": [
"react-app",
"react-app/jest",
"plugin:prettier/recommended"
],
"rules": {
"no-console": "warn"
},
"globals": {
"JSX": true
}
}
I had to remove plugins: ['@typescript-eslint'],
because I was getting: Error: "prettier/@typescript-eslint" has been merged into "prettier" in eslint-config-prettier 8.0.0
我不得不删除
plugins: ['@typescript-eslint'],
因为我得到: Error: "prettier/@typescript-eslint" has been merged into "prettier" in eslint-config-prettier 8.0.0
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.