首页 > 解决方案 > 无法在地图功能中推断类型

问题描述

作为将我的项目从 angular 5 迁移到 6 的一部分,我必须更新 RXJS6 做事的方式。

所以这

this.filteredList = this.autoComplete.valueChanges
.startWith(null)
.map(val => val ? this.filter(val) : this.list.slice());

改成这个

this.filteredList = this.autoComplete.valueChanges.pipe(
startWith(null),
map(val => val ? this.filter(val) : this.list.slice()));

似乎编译器无法再推断类型了

Severity    Code    Description Project File    Line    Suppression State
Error   TS2345  (TS) Argument of type '{}' is not assignable to parameter of 
type 'string'.  

我对所有pipeable操作员都得到了同样的结果——他们都不能说出他们正在接收的数据的类型。我该如何帮助它?

有趣的是,这似乎只是一个智能感知错误,代码可以编译并且工作正常。

标签: angularrxjsangular6rxjs6

解决方案


推荐阅读