Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

351
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda