mongodb - Meteor Mongo Collection 未使用 typescript 接口
问题描述
我想通过 typescript 接口描述 Mongo.Collection 模式,以严格检查 fetch、forEach 等的类型。
interface IChat {
_id: string;
name?: string
};
const Chats = new Mongo.Collection<IChat>('chat');
// (method) Mongo.Cursor<IChat>.forEach(callback: <T>(doc: T, index: number, cursor: Mongo.Cursor<T>) => void, thisArg?: any): void
Chats.find().forEach(c => {
console.log(c._id); // Property '_id' does not exist on type 'T'.
// Why "type T" if it should be the type IChat???
});
但面临下一个错误:Property '_id' does not exist on type 'T'.
我做错了什么?
解决方案
推荐阅读
- javascript - 如何使用范围滑块控制显示的内容(视频/图像)?
- git - 如何使用 maven 发布插件将发布推送到 github?
- r - 如何平滑R中的大部分垂直线?
- python - 在循环内绘制圆形函数时颜色没有响应
- reactjs - 如何从 JavaScript 中的静态方法调用非静态方法
- php - MediaWiki 样式表未加载 - 仅在 MainPage 上正常运行 // DependencyError: Unknown module: mediawiki.page.startup
- database - 打开ubuntu防火墙和mongod.conf后无法远程连接mongodb
- android - 对话框关闭时如何切换现有片段?
- python - 如何在 CSV 文件中查找单词的频率?
- json - vue axios中如何通过id删除数据