Sharvari Desai
Sharvari Desai

Reputation: 50

Basic Javascript filter function not working correctly in Angular2

This should be incredibly simple, but my filter function in Typescript keeps giving me an error. Here is my code:

highScores: HighScore[];

deletePlayer(email: string) {
      this.scoreDataService.deletePlayer(email)
         .subscribe(
            this.highScores = this.highScores.filter(highScore => highScore.email !== email)
          );
}

The filter function should simply return an array HighScore[], but instead, I keep getting this error:

Argument of type 'HighScore[] is not assignable to parameter of type 'NextObserver<Response> | ErrorObserver<Response> | CompletionObserver<Response> ...

Type 'HighScore[]' is not assignable to type '(value: Response) => void'. Tyope 'HighScore[]' provides no match for the signature '(value:Response): void'

The weirdest thing is that this code runs and works perfectly even with this error. Does anyone know what could be happening? Thank you in advance!

Upvotes: 0

Views: 324

Answers (1)

joews
joews

Reputation: 30330

subscribe expects a function argument:

this.scoreDataService.deletePlayer(email) 
  .subscribe(() => {
     this.highScores = this.highScores.filter(highScore => highScore.email !== email)
   });

Upvotes: 3

Related Questions