From 084c396e8d85da5450f50bb3a3631a8621d9eb21 Mon Sep 17 00:00:00 2001 From: Flam3rboy <34555296+Flam3rboy@users.noreply.github.com> Date: Wed, 7 Apr 2021 04:01:47 +0200 Subject: [PATCH] fix toObject type --- src/util/Database.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/util/Database.ts b/src/util/Database.ts index e17eeccb..5d9afab9 100644 --- a/src/util/Database.ts +++ b/src/util/Database.ts @@ -1,5 +1,5 @@ import "./MongoBigInt"; -import mongoose, { Collection, Connection } from "mongoose"; +import mongoose, { Collection, Connection, LeanDocument } from "mongoose"; import { ChangeStream, ChangeEvent, Long } from "mongodb"; import EventEmitter from "events"; import { Document } from "mongoose"; @@ -11,11 +11,13 @@ const connection = mongoose.createConnection(uri, { autoIndex: true, useNewUrlPa export default connection; -function transform(document: T) { +function transform(document: T) { + // @ts-ignore return document.toObject({ virtuals: true }); } -export function toObject(document: T | T[]) { +export function toObject(document: T): LeanDocument { + // @ts-ignore return Array.isArray(document) ? document.map((x) => transform(x)) : transform(document); }