【发布时间】:2017-04-24 07:13:29
【问题描述】:
我正在尝试使用通过
安装的 mongodb 类型npm install @types/mongodb -D
现在我想在这样的函数中使用类型
export default async function insertOne(collection:any, data:any):Promise<InsertOneWriteOpResult> {
let db = await state.db
let col = await db.collection(collection)
let result = await col.insertOne(data)
return result
}
我对 InsertOneWriteOpResult 的类型特别感兴趣。 但我收到打字稿编译器错误:
src/utils/mongodb/collection/insert-one.ts|5 col 17 error| Cannot find namespace 'InsertOneWriteOpResult'.
我在 typings.d.ts 中引用了类型文件
/// <reference path="./../node_modules/@types/mongodb/index.d.ts" />
在这个文件中我可以看到,接口被导出:
export interface InsertOneWriteOpResult {
insertedCount: number;
ops: Array<any>;
insertedId: ObjectID;
connection: any;
result: { ok: number, n: number }
}
所以我的问题是,我必须使用哪个命名空间来让 typescript 检查 InsertOptionsWriteOpResult?
【问题讨论】:
标签: node.js mongodb typescript typescript-typings