简体   繁体   中英

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 on address in address?.street ? ?

Eslint rules both for the .js and .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"
            }
          }
        }
      ]
    }

It looks like the es version is set to the default value. Optional chaining ( address?.street ) is ES2019. By default, ESLint expects ECMAScript 5 syntax. If you want to enable ES2019 syntax add this to parserOptions : ecmaVersion: '9' (or '2019' ) to your eslintrc ( link to docs ).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM