首页 > 解决方案 > 如何修复此错误无法调用类型缺少调用签名的表达式

问题描述

错误 :

[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();
      }

标签: javascriptangularjstypescriptfirebase-realtime-database

解决方案


item.payload是一个属性而不是一个函数,你应该看看你是否在你的 IDE 中跳转到它的定义:

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.


推荐阅读