代码之家  ›  专栏  ›  技术社区  ›  Idris.AH

非类型化函数调用不能接受类型参数

  •  0
  • Idris.AH  · 技术社区  · 6 年前

    我正在使用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 回复  |  直到 6 年前
        1
  •  1
  •   Tomas    6 年前

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