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

348
Views
Property 'filteredOptions' has no initializer and is not definitely assigned in the constructor

in my Angular app i have a component:

  filteredOptions: Observable<string[]>;

Following line give the error:

Property 'filteredOptions' has no initializer and is not definitely assigned in the constructor.

28   filteredOptions: Observable<string[]>;
over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

it's because typescript 2.7.2 included a strict class checking where all properties should be declared in constructor. So to work around that you can:

  • just add a bang sign (!) like: name!:string;
  • adding "strictPropertyInitialization": false to your compiler options.
  • use filteredOptions: Observable<string[]> | undefined;
  • use filteredOptions?: Observable<string[]>

more details:

  • name!:string; : compiler trust me on this, I will guarantee that it will not be undefined (can cause unpredicted behavior)
  • "strictPropertyInitialization": false: compiler stop your strict check everywhere please
  • the last two solutions: compiler, filteredOptions might or might not have a value. In that case, it's your responsibility to handle the undefined value in your case (use ?. in your HTML templates, null and undefined check...etc.)
over 4 years ago · Santiago Trujillo 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!