| |
| |
| |
| |
| @@ -1,4 +1,4 @@ |
| -import { Schema, model, Types, InferSchemaType, FlattenMaps } from 'mongoose'; |
| +import { Schema, model, Types, InferSchemaType, FlattenMaps, Require_id } from 'mongoose'; |
| import { expectAssignable, expectError, expectType } from 'tsd'; |
| |
| function gh10345() { |
| @@ -206,3 +206,107 @@ async function gh13382() { |
| const res = await Test.updateOne({}, { name: 'bar' }).lean(); |
| expectAssignable<{ matchedCount: number, modifiedCount: number }>(res); |
| } |
| + |
| +async function gh13702_findById_lean_option() { |
| + interface User { name: string; } |
| + const UserModel = model<User>('User', new Schema({ name: String })); |
| + |
| + const a = await UserModel.findById('id', undefined, { lean: true }); |
| + const b = await UserModel.findById('id').lean(); |
| + expectType<typeof b>(a); |
| + expectType<(FlattenMaps<User> & { _id: Types.ObjectId }) | null>(a); |
| + |
| + const a2 = await UserModel.findById('id', null, { lean: true }); |
| + expectType<(FlattenMaps<User> & { _id: Types.ObjectId }) | null>(a2); |
| +} |
| + |
| +async function gh13702_findById_no_lean_preserves_hydrated() { |
| + interface User { name: string; } |
| + const UserModel = model<User>('User', new Schema({ name: String })); |
| + |
| + const a = await UserModel.findById('id'); |
| + if (a) { |
| + |
| + expectAssignable<Function>(a.save); |
| + } |
| +} |
| + |
| +async function gh13702_findOne_lean_option() { |
| + interface User { name: string; } |
| + const UserModel = model<User>('User', new Schema({ name: String })); |
| + |
| + const a = await UserModel.findOne({}, undefined, { lean: true }); |
| + const b = await UserModel.findOne({}).lean(); |
| + expectType<typeof b>(a); |
| + expectType<(FlattenMaps<User> & { _id: Types.ObjectId }) | null>(a); |
| +} |
| + |
| +async function gh13702_find_lean_option() { |
| + interface User { name: string; } |
| + const UserModel = model<User>('User', new Schema({ name: String })); |
| + |
| + const a = await UserModel.find({}, undefined, { lean: true }); |
| + const b = await UserModel.find({}).lean(); |
| + expectType<typeof b>(a); |
| + expectType<Array<FlattenMaps<User> & { _id: Types.ObjectId }>>(a); |
| +} |
| + |
| +async function gh13702_findOneAndDelete_lean_option() { |
| + interface User { name: string; } |
| + const UserModel = model<User>('User', new Schema({ name: String })); |
| + |
| + const a = await UserModel.findOneAndDelete({}, { lean: true }); |
| + const b = await UserModel.findOneAndDelete({}).lean(); |
| + expectType<typeof b>(a); |
| + expectType<(FlattenMaps<User> & { _id: Types.ObjectId }) | null>(a); |
| +} |
| + |
| +async function gh13702_findOneAndUpdate_lean_option() { |
| + interface User { name: string; } |
| + const UserModel = model<User>('User', new Schema({ name: String })); |
| + |
| + const a = await UserModel.findOneAndUpdate({}, { name: 'x' }, { lean: true }); |
| + const b = await UserModel.findOneAndUpdate({}, { name: 'x' }).lean(); |
| + expectType<typeof b>(a); |
| + expectType<(FlattenMaps<User> & { _id: Types.ObjectId }) | null>(a); |
| +} |
| + |
| +async function gh13702_findOneAndReplace_lean_option() { |
| + interface User { name: string; } |
| + const UserModel = model<User>('User', new Schema({ name: String })); |
| + |
| + const a = await UserModel.findOneAndReplace({}, { name: 'x' }, { lean: true }); |
| + const b = await UserModel.findOneAndReplace({}, { name: 'x' }).lean(); |
| + expectType<typeof b>(a); |
| + expectType<(FlattenMaps<User> & { _id: Types.ObjectId }) | null>(a); |
| +} |
| + |
| +async function gh13702_findByIdAndDelete_lean_option() { |
| + interface User { name: string; } |
| + const UserModel = model<User>('User', new Schema({ name: String })); |
| + |
| + const a = await UserModel.findByIdAndDelete('id', { lean: true }); |
| + const b = await UserModel.findByIdAndDelete('id').lean(); |
| + expectType<typeof b>(a); |
| + expectType<(FlattenMaps<User> & { _id: Types.ObjectId }) | null>(a); |
| +} |
| + |
| +async function gh13702_findByIdAndRemove_lean_option() { |
| + interface User { name: string; } |
| + const UserModel = model<User>('User', new Schema({ name: String })); |
| + |
| + const a = await UserModel.findByIdAndRemove('id', { lean: true }); |
| + const b = await UserModel.findByIdAndRemove('id').lean(); |
| + expectType<typeof b>(a); |
| + expectType<(FlattenMaps<User> & { _id: Types.ObjectId }) | null>(a); |
| +} |
| + |
| +async function gh13702_findByIdAndUpdate_lean_option() { |
| + interface User { name: string; } |
| + const UserModel = model<User>('User', new Schema({ name: String })); |
| + |
| + const a = await UserModel.findByIdAndUpdate('id', { name: 'x' }, { lean: true }); |
| + const b = await UserModel.findByIdAndUpdate('id', { name: 'x' }).lean(); |
| + expectType<typeof b>(a); |
| + expectType<(FlattenMaps<User> & { _id: Types.ObjectId }) | null>(a); |
| +} |
| |
| new file mode 100644 |
| |
| |
| |
| @@ -0,0 +1,3 @@ |
| +{ |
| + "test_commands": ["./node_modules/.bin/tsd"] |
| +} |
| |
| new file mode 100755 |
| |
| |
| @@ -0,0 +1,8 @@ |
| +#!/usr/bin/env bash |
| + |
| +set -uo pipefail |
| +cd /testbed |
| +rc=0 |
| +./node_modules/.bin/tsd |
| +rc=$(( rc | $? )) |
| +exit $rc |
|
|