1

I am facing an issue with a project I cloned.I have the following code created using this project

https://github.com/enuchi/React-Google-Apps-Script

export interface Vehicle {
  wheels: number;
  insurance?: string;
}
export default class Car {
  wheels: number;
  insurance?: string;
}

VS code throws an error on the insurance? line in the class. It doesn't have an issue with the same in the interface, just the class

It looks like eslint is causing problems. However, the project compiles just fine.

Parsing error: Unexpected token

  5 | export default class Car {
  6 |   wheels: number;
> 7 |   insurance?: string;
    |            ^
  8 | }
  9 |eslint

Eslintrc

{
  "root": true,
  "parser": "babel-eslint",
  "extends": ["airbnb-base", "plugin:prettier/recommended", "plugin:@typescript-eslint/recommended", "plugin:@typescript-eslint/recommended"],
  "plugins": ["prettier","@typescript-eslint"],
  "rules": {
    "prettier/prettier": "error",
    "camelcase": "warn",
    "import/prefer-default-export": "warn",
    "import/no-extraneous-dependencies": "warn",
    "prefer-object-spread": "warn",
    "spaced-comment":"off"
  }
}

tsconfig

{
  "compilerOptions": {
    "target": "es2019",                          /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */
    "module": "commonjs",                     /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */

    "types": ["gas-types-detailed", "node"],
    "jsx": "react",
    "esModuleInterop": true,
    // "preserveSymlinks": true,              /* Do not resolve the real path of symlinks. */
    // "allowUmdGlobalAccess": true,          /* Allow accessing UMD globals from modules. */

    /* Source Map Options */
    // "sourceRoot": "",                      /* Specify the location where debugger should locate TypeScript files instead of source locations. */
    // "mapRoot": "",                         /* Specify the location where debugger should locate map files instead of generated locations. */
    // "inlineSourceMap": true,               /* Emit a single file with source maps instead of having a separate file. */
    // "inlineSources": true,                 /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */

    /* Experimental Options */
     "experimentalDecorators": true,        /* Enables experimental support for ES7 decorators. */
    "emitDecoratorMetadata": true,         /* Enables experimental support for emitting type metadata for decorators. */
    "resolveJsonModule": true,
    /* Advanced Options */
    "skipLibCheck": true,                     /* Skip type checking of declaration files. */
    "forceConsistentCasingInFileNames": true  /* Disallow inconsistently-cased references to the same file. */

  }
}

babelrc

{
  "presets": [
    [
      "@babel/env",
      {
        "modules": false
      }
    ],

  ],
  "plugins": [
    "transform-es3-property-literals",
    "transform-es3-member-expression-literals",
    "@babel/plugin-proposal-class-properties",
    "@babel/plugin-proposal-object-rest-spread",
    "@babel/plugin-transform-object-assign"
  ]
}

SoWhat
  • 5,564
  • 2
  • 28
  • 59
  • I think you haven't set up ESLint for use with TypeScript. – Julia Mar 07 '21 at 23:06
  • i did add "extends": ["airbnb-base", "plugin:prettier/recommended", "plugin:@typescript-eslint/recommended", "plugin:@typescript-eslint/recommended"], – SoWhat Mar 07 '21 at 23:07

1 Answers1

0

I'm not sure that your linting configuration will work for Typescript, due to the babel-eslint parser.

The getting started docs for typescript-eslint show a different configuration: https://github.com/typescript-eslint/typescript-eslint/blob/master/docs/getting-started/linting/README.md

This stack overflow answer might also be helpful: https://stackoverflow.com/a/62535953/8069575

cdimitroulas
  • 2,380
  • 1
  • 15
  • 22