这应该非常简单,但我在Typescript中的过滤器功能一直给我一个错误。这是我的代码:
highScores: HighScore[];
deletePlayer(email: string) {
this.scoreDataService.deletePlayer(email)
.subscribe(
this.highScores = this.highScores.filter(highScore => highScore.email !== email)
);
}
过滤函数应该只返回一个数组HighScore [],但是我不断收到此错误:
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'
最奇怪的是,即使出现此错误,此代码也能正常运行。有谁知道会发生什么?提前谢谢!
答案 0 :(得分:2)
subscribe
需要一个函数参数:
this.scoreDataService.deletePlayer(email)
.subscribe(() => {
this.highScores = this.highScores.filter(highScore => highScore.email !== email)
});