[英]Parsing error: Expression expected. eslint
interface Address {
street: string,
}
export const getAddress = (address: Address | null) : string =>
address?.street ? `${address?.street}`
: '0000 Default Dr';
Does anybody know am I getting Parsing error: Expression expected. eslint
有谁知道我收到
Parsing error: Expression expected. eslint
Parsing error: Expression expected. eslint
on address
in address?.street ?
Parsing error: Expression expected. eslint
on address
in address?.street ?
? ?
Eslint rules both for the .js
and .ts
: .js
和.ts
的 Eslint 规则:
{
"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"
}
}
}
]
}
It looks like the es version is set to the default value.看起来 es 版本设置为默认值。 Optional chaining (
address?.street
) is ES2019.可选链接(
address?.street
)是 ES2019。 By default, ESLint expects ECMAScript 5 syntax.默认情况下,ESLint 需要 ECMAScript 5 语法。 If you want to enable ES2019 syntax add this to
parserOptions
: ecmaVersion: '9'
(or '2019'
) to your eslintrc ( link to docs ).如果您想启用 ES2019 语法,请将其添加到
parserOptions
: ecmaVersion: '9'
(或'2019'
)到您的 eslintrc ( 链接到文档)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.