You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
*[Allow `null` For Optional Fields in TypeScript](#allow-null-for-optional-fields-in-typescript)
19
20
20
21
<h2id="removed-rawresult-option-for-findoneandupdate"><ahref="#removed-rawresult-option-for-findoneandupdate">Removed <code>rawResult</code> option for <code>findOneAndUpdate()</code></a></h2>
21
22
@@ -59,4 +60,20 @@ Use `findOneAndDelete()` instead.
59
60
<h2id="removed-id-setter"><ahref="#removed-id-setter">Removed id Setter</a></h2>
60
61
61
62
In Mongoose 7.4, Mongoose introduced an `id` setter that made `doc.id = '0'.repeat(24)` equivalent to `doc._id = '0'.repeat(24)`.
62
-
In Mongoose 8, that setter is now removed.
63
+
In Mongoose 8, that setter is now removed.
64
+
65
+
<h2id="allow-null-for-optional-fields-in-typescript"><ahref="#allow-null-for-optional-fields-in-typescript">Allow <code>null</code> For Optional Fields in TypeScript</a></h2>
66
+
67
+
In Mongoose 8, automatically inferred schema types in TypeScript allow `null` for optional fields.
68
+
In Mongoose 7, optional fields only allowed `undefined`, not `null`.
69
+
70
+
```typescript
71
+
const schema =newSchema({ name: String });
72
+
const TestModel =model('Test', schema);
73
+
74
+
const doc =newTestModel();
75
+
76
+
// In Mongoose 8, this type is `string | null | undefined`.
77
+
// In Mongoose 7, this type is `string | undefined`
0 commit comments