diff --git a/test/types/lean.test.ts b/test/types/lean.test.ts index b6f9e5380..caa572c29 100644 --- a/test/types/lean.test.ts +++ b/test/types/lean.test.ts @@ -1,4 +1,5 @@ -import { Schema, model, Types, InferSchemaType, FlattenMaps } from 'mongoose'; +import { Schema, model, Types, InferSchemaType, FlattenMaps, UpdateWriteOpResult } from 'mongoose'; +import { DeleteResult } from 'mongodb'; import { expectAssignable, expectError, expectType } from 'tsd'; function gh10345() { @@ -196,3 +197,81 @@ async function gh13345_3() { const place = await PlaceModel.findOne().lean().orFail().exec(); expectAssignable(place); } + +async function gh13345_lean_updateOne() { + interface IDBUser { + name: string; + email: string; + } + const UserModel = model('GH13345UpdateOne', new Schema({ name: String, email: String })); + + const res = await UserModel.updateOne({}, { name: 'foo' }).lean(); + expectType(res); + + const resMany = await UserModel.updateMany({}, { name: 'foo' }).lean(); + expectType(resMany); +} + +async function gh13345_lean_deleteOne() { + interface IDBUser { + name: string; + } + const UserModel = model('GH13345DeleteOne', new Schema({ name: String })); + + const res = await UserModel.deleteOne({}).lean(); + expectType(res); + + const resMany = await UserModel.deleteMany({}).lean(); + expectType(resMany); +} + +async function gh13345_lean_count() { + interface IDBUser { + name: string; + } + const UserModel = model('GH13345Count', new Schema({ name: String })); + + const cnt = await UserModel.count({}).lean(); + expectType(cnt); + + const cntDocs = await UserModel.countDocuments({}).lean(); + expectType(cntDocs); + + const est = await UserModel.estimatedDocumentCount().lean(); + expectType(est); +} + +async function gh13345_lean_distinct() { + interface IDBUser { + name: string; + } + const UserModel = model('GH13345Distinct', new Schema({ name: String })); + + const values = await UserModel.distinct('name').lean(); + expectType(values); +} + +async function gh13345_lean_findOne_preserved() { + interface IDBUser { + name: string; + email: string; + } + const UserModel = model('GH13345FindOne', new Schema({ name: String, email: String })); + + const doc = await UserModel.findOne({}).lean(); + if (doc) { + expectType(doc.name); + expectType(doc.email); + } +} + +async function gh13345_lean_find_preserved() { + interface IDBUser { + name: string; + } + const UserModel = model('GH13345Find', new Schema({ name: String })); + + const docs = await UserModel.find({}).lean(); + expectType(docs[0].name); + expectType(docs[0]._id); +} diff --git a/test_commands.json b/test_commands.json new file mode 100644 index 000000000..0f7dbefd0 --- /dev/null +++ b/test_commands.json @@ -0,0 +1,3 @@ +{ + "test_commands": ["npx tsd"] +} diff --git a/mimo_test_command.sh b/mimo_test_command.sh new file mode 100755 --- /dev/null +++ b/mimo_test_command.sh @@ -0,0 +1,8 @@ +#!/usr/bin/env bash + +set -uo pipefail +cd /testbed +rc=0 +npx tsd +rc=$(( rc | $? )) +exit $rc