Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

160
Views
Creating property inside constructor with Typescript

I have a javascript code that works perfectly:

class myController {
   constructor () {
      this.language = 'english'
   }
}

BUT when I try to do the same with Typescript

export default class myController {
  constructor () {
    this.language = 'english'
  }
}

It gives me the following error:

Property 'language' does not exist on type 'myController'.ts(2339)

Why exactly this happen when trying to create a property for myController?
What would be the right way to do so?

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Because you are trying to set a property which does not exist in the class as it says, declare it somewhere in the class before you try set it, i.e:

export default class myController {
  private language: string;
  constructor () {
    this.language = 'english'
  }
}
about 4 years ago · Juan Pablo Isaza Report

0

It needs to be declared as a Property on the type (typically before the constructor):

export default class myController {
  language: string;
  constructor () {
    this.language = 'english'
  }
}
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!