未类型化的函数调用可能不接受类型参数

时间:2018-07-22 19:53:57

标签: angular rxjs observable google-cloud-firestore angular6

我正在使用Angular6,并尝试在此过滤器功能中获取文档内容。我的代码片段的最后一行给了我错误“未键入的函数调用可能不接受类型参数”。不确定为什么会收到此错误...也许无法在过滤器函数中使用...?

构造函数:

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}`);
      })
    });

1 个答案:

答案 0 :(得分:1)

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}`);
  })
  )
});