简体   繁体   中英

Untyped function calls may not accept type arguments

I am using Angular6 and trying to get the document content within this filter function. The very last line of my code snippet is giving me the error "Untyped function calls may not accept type arguments". Not sure why I'm getting this error... maybe it cannot be used within filter function...?

Constructor:

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

Filtering:

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 signature expects a type of Observable<T> to be returned. In your case you are returning only <T> (in your case is any as this is control output). Try to wrap returned value with 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}`);
  })
  )
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM