interface Address {
street: string,
}
export const getAddress = (address: Address | null) : string =>
address?.street ? `${address?.street}`
: '0000 Default Dr';
有人知道我在address?.street ?
中的address
上得到Parsing error: Expression expected. eslint
吗?
Eslint针对.js
和.ts
的规则:
{
"extends": [
"plugin:cypress/recommended",
"plugin:@typescript-eslint/recommended"
],
"overrides":
{
"files": ["**/*.{ts,tsx}"],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"project": "./tsconfig.json"
},
"plugins": ["@typescript-eslint", "prettier", "react-hooks", "jsx-a11y"],
"extends": [
"eslint:recommended",
"react-app",
"plugin:@typescript-eslint/recommended",
"plugin:@typescript-eslint/recommended-requiring-type-checking",
"prettier"
],
"rules": {
"@typescript-eslint/explicit-function-return-type": "off",
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/no-shadow": "off",
"no-empty-function": 0,
"@typescript-eslint/no-empty-function": "off",
"@typescript-eslint/explicit-module-boundary-types": "off",
"@typescript-eslint/no-non-null-assertion": "off",
"no-use-before-define": "off",
"@typescript-eslint/no-use-before-define": ["error"]
},
"settings": {
"import/parsers": {
"@typescript-eslint/parser": [".ts", ".tsx"]
},
"import/resolver": {
"typescript": {}
},
"react": {
"version": "detect"
}
}
}
]
}
2条答案
按热度按时间ldxq2e6h1#
看起来ES版本设置为默认值。可选的链接(
address?.street
)是ES2019。默认情况下,ESLint需要ECMAScript 5语法。如果你想启用ES2019语法,请将以下内容添加到parserOptions
:ecmaVersion: '9'
(或'2019'
)到eslintrc(链接到文档)。b09cbbtk2#
有多种原因可能导致此错误-> link to article
在你的例子中,在不同的行中声明const和variable export是可行的。
除了在链接的文章中提到的,以及具体到我的情况,我得到了这个错误,当我链接语句不使用括号,并在最后添加了一个行内注解。
这是我写的抛出错误的原始语句:
解决方案是将注解从末尾删除,并将其放在单独的一行:
希望这有帮助!编码快乐!