javascript - 如何修复此错误无法调用类型缺少调用签名的表达式
问题描述
错误 :
[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();
}
解决方案
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
.
推荐阅读
- javascript - 根据 div:contains 值更改数据集属性
- reactjs - 中继 11 中的“fetchQuery.toPromise()”:什么是 3D 数据?
- reactjs - Material UI 对话框组件 - 如何显示它?
- odata - OData - 一对多过滤所有没有数据的记录
- javascript - 调用 page.waitForTimeout 后,Puppeteer 无法单击元素
- python - 添加基于 pytest 的框架作为依赖项
- node.js - 如何使用node js ad mongodb制作一个针对多个国家的分类广告网站?
- python - Websocket 数据流索引
- java - Java Saxon 10.5 XSL 3 转换,未找到 href 文件
- javascript - 如何使用 Next.js 将 PNG 徽标添加到 Tailwind CSS 导航栏?