I encountered a problem with a project I cloned. Below is the code snippet 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;
}
An error is being thrown by VS Code on the line with `insurance?` in the class. Interestingly, there is no issue with the same syntax in the interface.
It seems like eslint is causing the trouble. Nevertheless, the project compiles without any problems.
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",
"module": "commonjs",
"types": ["gas-types-detailed", "node"],
"jsx": "react",
"esModuleInterop": true,
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"resolveJsonModule": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true
}
}
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"
]
}