如何解决此错误,无法调用类型缺少调用签名的表达式

时间:2018-10-08 16:38:53

标签: javascript angularjs typescript firebase-realtime-database

错误:

[ts] Cannot invoke an expression whose type lacks a call signature. Type 'DatabaseSnapshot<any>' has no compatible call signatures.
(parameter) item: AngularFireAction<DatabaseSnapshot<any>>

文件消费服务

**Error is at ...Item.payLoad().val()**
 constructor(private service: EmployeeService) { }
  ngOnInit() {
    this.service.getEmployees().subscribe(list => {
      let array = list.map(item => {
        return { $key: item.key, **...item.payload().val()** }
      })
    });
  }
**Method-II**
    getEmployees() {
        this.employeeList = this.db.list('employees');
        return this.employeeList.snapshotChanges();
      }

1 个答案:

答案 0 :(得分:0)

item.payload是一个属性,而不是一个函数,如您所见,是否在您的IDE中跳至its definition

export interface Action<T> {
  type: ListenEvent;
  payload: T;  // <---
};

export interface AngularFireAction<T> extends Action<T> {
  prevKey: string | null | undefined;
  key: string | null;
}

因此,您应使用item.payload而不要调用它:删除item.payload之后的括号。