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

250
Visualizações
The 'this' context of type 'void' is not assignable to method's 'this' of type 'Observable<string>'

I am getting this error in angular's autocomplete example. Here is the code:

ngOnInit() {
      this.filteredOptions = this.myControl.valueChanges
          .pipe(
            startWith(''),
            map(val => this.filter(val))
          );
}

The error is spawn on startWith. I am also getting an error in the second val. It says:

Argument of type '{}' is not assignable to parameter of type 'string'

The function is:

 filter(val: string): string[] {
    return this.options.filter(option =>
      option.toLowerCase().indexOf(val.toLowerCase()) === 0);
  }

HINT: There is something with mixed controls or imports. I am not sure but when I create a new component everything works fine.

over 4 years ago · Santiago Trujillo
2 Respostas
Responde à pergunta

0

I just had the same issue and it turns out I was importing map and startWith from the wrong directory.

import {map, startWith} from "rxjs/operators";

Use this to import both map and startWith and it should work and compile.

over 4 years ago · Santiago Trujillo Relatório

0

My case was that I loaded take(1) automatically by autopopulating from rxjs/compat/take but not from rxjs/operators, and catch this issue. Not so obvious thing :)

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