无类型函数调用可能不接受类型参数

Untyped function calls may not accept type arguments

我正在使用 Angular6 并尝试在此过滤器函数中获取文档内容。我的代码片段的最后一行给出了错误 "Untyped function calls may not accept type arguments"。不确定为什么会出现此错误...也许它不能在过滤器功能中使用...?

构造函数:

constructor(private afs : AngularFirestore, private authService : AuthService) { 
  //Get user collection on initialise
  this.userCollection = this.afs.collection('users');
}

过滤:

this.userCollection = this.afs.collection<User>('users', ref => {
      console.log(ref);
      return ref
    })

    this.usersOnSearch = this.userCollection.valueChanges();

    this.usersOnSearch.flatMap(user => {
      return user.filter(function(value) {
        let subjectTrue : boolean = false;
        let levelTrue : boolean = false;
        let docID : string = value.user_subjects.id;
        let userLevelPriceDocument :  AngularFirestoreDocument<UserSubjects>;
        userLevelPriceDocument = this.afs.doc<UserSubjects>(`user_subjects/${docID}`);
      })
    });

flatMap 签名期望返回 Observable<T> 类型。在你的情况下你只返回 <T> (在你的情况下是 any 因为这是控制输出)。尝试用 Observable.of() 包装返回值:

this.usersOnSearch.flatMap(user => {
  return Observable.of( user.filter(function(value) {
    let subjectTrue : boolean = false;
    let levelTrue : boolean = false;
    let docID : string = value.user_subjects.id;
    let userLevelPriceDocument :  AngularFirestoreDocument<UserSubjects>;
    userLevelPriceDocument = this.afs.doc<UserSubjects>(`user_subjects/${docID}`);
  })
  )
});