| |
| |
| |
| |
| @@ -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>(place); |
| } |
| + |
| +async function gh13345_lean_updateOne() { |
| + interface IDBUser { |
| + name: string; |
| + email: string; |
| + } |
| + const UserModel = model<IDBUser>('GH13345UpdateOne', new Schema<IDBUser>({ name: String, email: String })); |
| + |
| + const res = await UserModel.updateOne({}, { name: 'foo' }).lean(); |
| + expectType<UpdateWriteOpResult>(res); |
| + |
| + const resMany = await UserModel.updateMany({}, { name: 'foo' }).lean(); |
| + expectType<UpdateWriteOpResult>(resMany); |
| +} |
| + |
| +async function gh13345_lean_deleteOne() { |
| + interface IDBUser { |
| + name: string; |
| + } |
| + const UserModel = model<IDBUser>('GH13345DeleteOne', new Schema<IDBUser>({ name: String })); |
| + |
| + const res = await UserModel.deleteOne({}).lean(); |
| + expectType<DeleteResult>(res); |
| + |
| + const resMany = await UserModel.deleteMany({}).lean(); |
| + expectType<DeleteResult>(resMany); |
| +} |
| + |
| +async function gh13345_lean_count() { |
| + interface IDBUser { |
| + name: string; |
| + } |
| + const UserModel = model<IDBUser>('GH13345Count', new Schema<IDBUser>({ name: String })); |
| + |
| + const cnt = await UserModel.count({}).lean(); |
| + expectType<number>(cnt); |
| + |
| + const cntDocs = await UserModel.countDocuments({}).lean(); |
| + expectType<number>(cntDocs); |
| + |
| + const est = await UserModel.estimatedDocumentCount().lean(); |
| + expectType<number>(est); |
| +} |
| + |
| +async function gh13345_lean_distinct() { |
| + interface IDBUser { |
| + name: string; |
| + } |
| + const UserModel = model<IDBUser>('GH13345Distinct', new Schema<IDBUser>({ name: String })); |
| + |
| + const values = await UserModel.distinct<string>('name').lean(); |
| + expectType<string[]>(values); |
| +} |
| + |
| +async function gh13345_lean_findOne_preserved() { |
| + interface IDBUser { |
| + name: string; |
| + email: string; |
| + } |
| + const UserModel = model<IDBUser>('GH13345FindOne', new Schema<IDBUser>({ name: String, email: String })); |
| + |
| + const doc = await UserModel.findOne({}).lean(); |
| + if (doc) { |
| + expectType<string>(doc.name); |
| + expectType<string>(doc.email); |
| + } |
| +} |
| + |
| +async function gh13345_lean_find_preserved() { |
| + interface IDBUser { |
| + name: string; |
| + } |
| + const UserModel = model<IDBUser>('GH13345Find', new Schema<IDBUser>({ name: String })); |
| + |
| + const docs = await UserModel.find({}).lean(); |
| + expectType<string>(docs[0].name); |
| + expectType<Types.ObjectId>(docs[0]._id); |
| +} |
| |
| new file mode 100644 |
| |
| |
| |
| @@ -0,0 +1,3 @@ |
| +{ |
| + "test_commands": ["npx tsd"] |
| +} |
| |
| new file mode 100755 |
| |
| |
| @@ -0,0 +1,8 @@ |
| +#!/usr/bin/env bash |
| + |
| +set -uo pipefail |
| +cd /testbed |
| +rc=0 |
| +npx tsd |
| +rc=$(( rc | $? )) |
| +exit $rc |
|
|