我正在尝试为此找到一种类型:export const connectToDatabase = ()/* here */ => mongoose.connect(uri, { useNewUrlParser: true, useUnifiedTopology: true,});到目前为止,我的代码编辑器建议这样做:export const connectToDatabase = (): Promise<typeof mongoose> => mongoose.connect(uri, { useNewUrlParser: true, useUnifiedTopology: true,});这很愚蠢。我不希望这种类型存在Promise<typeof mongoose>,而且它不可能是所需的解决方案。那么这里的正确类型是什么?我所能找到的只是ConnectionUseDbOptions,ConnectionOptions这是行不通的。那么这里正确的类型是什么?
1 回答

慕哥6287543
TA贡献1831条经验 获得超10个赞
根据:index.d.ts_@types/mongoose
type Mongoose = typeof mongoose;
...
export function connect(uris: string, options: ConnectionOptions, callback: (err: mongodb.MongoError) => void): Promise<Mongoose>;
export function connect(uris: string, callback: (err: mongodb.MongoError) => void): Promise<Mongoose>;
export function connect(uris: string, options?: ConnectionOptions): Promise<Mongoose>;
所以返回类型肯定是Promise<Mongoose>orPromise<type of mongoose>
添加回答
举报
0/150
提交
取消