AdithyaSK's picture
AdithyaSK HF Staff
Add files using upload-large-folder tool
f3ee72f verified
|
Raw History Blame Contribute Delete
1.45 kB

Fix the following issue:

Typescript: Wrong return type when using lean in different way

Prerequisites

  • I have written a descriptive issue title
  • I have searched existing issues to ensure the bug has not already been reported

Mongoose version

6.X.X - 7.X.X

Node.js version

at least 16

MongoDB server version

at least 4

Typescript version (if applicable)

4.7 - latest

Description

The return type of

const a = await Model.findById('my-id', undefined, { lean: true })

is the same as

const a = await Model.findById('my-id')

it's:

// ^? const a: (mongoose.Document<unknown, {}, { name: string; }> & { name: string; } & { _id: mongoose.Types.ObjectId; }) | null

Steps to Reproduce

See ts playground

Expected Behavior

The return type should be the same as

const a = await Model.findById('a').lean()

it's:

// ^? const a: (mongoose.FlattenMaps<{ name: string; }> & { _id: mongoose.Types.ObjectId; }) | null