Typescript Constructor Parameters. Parsing error: Unexpected reserved word 'public'

I wanted to create class in typescritp + react
I decided to use Typescript constructor parameters
But I have an error during compilation when i do that.

That is my UserData class

enum SecurityRole {
    USER = "USER",
    ADMIN= "ADMIN"
}
export class UserData {
    constructor(public name: string, readonly securityRole = SecurityRole.USER) { }
}
export const createUserDataFromJson = (json: any): UserData => {
    console.log(`user from json : ` + json)
    return new UserData(json.name, json.securityRole)
}

But i have received an error:

  Line 8:17:  Parsing error: Unexpected reserved word 'public'

   6 | }
   7 | export class UserData {
>  8 |     constructor(public name: string, readonly securityRole = SecurityRole.USER) { }
     |                 ^
   9 | }
  10 | export const createUserDataFromJson = (json: any): UserData => {
  11 |     console.log(`user from json : ` + json)

I figured that it might be someting with tsconfig.json so here it is:

{
  "compilerOptions": {
    "target": "ESNext",
    "module": "esnext",
    "strict": true,
    "esModuleInterop": true,
    "forceConsistentCasingInFileNames": true,
    "lib": [
      "dom",
      "dom.iterable",
      "esnext"
    ],
    "allowJs": true,
    "skipLibCheck": true,
    "allowSyntheticDefaultImports": true,
    "moduleResolution": "node",
    "resolveJsonModule": true,
    "isolatedModules": true,
    "noEmit": true,
    "jsx": "react-jsx",
    "noUnusedLocals": true,
    "noUnusedParameters": true,
    "noImplicitReturns": true,
    "noFallthroughCasesInSwitch": true
  },
  "include": [
    "src"
  ]
}

I am using npm run build this is react-scripts build in my project (4.0.2)

npm version 6.14.6
node version v12.18.3

Have i done anything wrong there? or is it something with my project settings?

37 thoughts on “Typescript Constructor Parameters. Parsing error: Unexpected reserved word 'public'”

  1. I was manage to fix that by adding eslintConfig to my package.json

     "eslintConfig": {
        "extends": [
          "react-app",
          "react-app/jest"
        ]
      },
    
    Reply
  2. positive words related to mental health community colleges near me with nursing programs , positive words verbs. positive words of encouragement lyrica 75 mg lyrica pills , community america wichita ks community forklift community bridges board of directors , culture yogurt brooklyn planning process la gi? community health center stamford ct positive reinforcement questionnaire, community bible church lancaster pa social kitchen menu.
    community college teacher salary , community action utica ny social goods followers enhanced fallout 3.

    Reply
  3. i leap office software free download drawing program website to buy Autocad 2020 design software computer requirements. office planning software free office tab software free download engeeeneringu#$sssaunnplus , 2020 outback software update. software vidmate 2020, free synth software 2020 2020 software developer jobs microsoft office 2020 software download. software intern winter 2020 ca office software free download, hindi leap office software free download.

    Reply

Leave a Comment