From e45aed2f51238c421d26f3c3308d9dcf67b57fcd Mon Sep 17 00:00:00 2001 From: Simon Tretter Date: Thu, 14 Nov 2019 00:01:10 +0100 Subject: [PATCH] [mongoose] fixes lean return type (#40335) * [mongoose] fixes lean return type commit https://github.com/DefinitelyTyped/DefinitelyTyped/commit/c74f860f8b80bb5542fbdafa0a81e260f2fec147#diff-ec6e6a45ee09ed93f5d81cb304c5a0b3 introduced typings for lean (instead of any). I like this approach, but it breaks old code, because type script assume T is undefined in this case. Also it didn't respect find or findOne and always used T directly. This approach fixes therefore two issues: - by default (if no type is provided), it is any again (backswards compatiblity) - Depending on the used functino it either returns the given type or an array of the given type. * fix(lean): it can also return null --- types/mongoose/index.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/types/mongoose/index.d.ts b/types/mongoose/index.d.ts index 165fc24fae..517185b55a 100644 --- a/types/mongoose/index.d.ts +++ b/types/mongoose/index.d.ts @@ -2000,7 +2000,7 @@ declare module "mongoose" { * getters/setters or other Mongoose magic applied. * @param {Boolean|Object} bool defaults to true */ - lean(bool?: boolean | object): Query & QueryHelpers; + lean

(bool?: boolean | object): Query ? P[] : (P | null)> & QueryHelpers; /** Specifies the maximum number of documents the query will return. Cannot be used with distinct() */ limit(val: number): this;