File size: 3,348 Bytes
197607f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
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>(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);
+}
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