Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

349
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda