Skip to content

Commit c1109ac

Browse files
authored
Merge pull request #13723 from Automattic/IslandRhythms/backport-13515
backport pull 13515
2 parents d4a1080 + 557a472 commit c1109ac

File tree

5 files changed

+30
-3
lines changed

5 files changed

+30
-3
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
"eslint-plugin-markdown": "^3.0.0",
5151
"eslint-plugin-mocha-no-only": "1.1.1",
5252
"express": "^4.18.1",
53+
"fs-extra": "~11.1.1",
5354
"highlight.js": "11.7.0",
5455
"lodash.isequal": "4.5.0",
5556
"lodash.isequalwith": "4.4.0",
@@ -67,8 +68,7 @@
6768
"tsd": "0.25.0",
6869
"typescript": "4.9.5",
6970
"uuid": "9.0.0",
70-
"webpack": "5.75.0",
71-
"fs-extra": "~11.1.1"
71+
"webpack": "5.75.0"
7272
},
7373
"directories": {
7474
"lib": "./lib/mongoose"

test/types/mongo.test.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import * as mongoose from 'mongoose';
2+
import { expectType } from 'tsd';
3+
import * as bson from 'bson';
4+
5+
function gh12537() {
6+
const schema = new mongoose.Schema({ test: String });
7+
const model = mongoose.model('Test', schema);
8+
9+
const doc = new model({});
10+
11+
const v = new bson.ObjectId('somehex');
12+
expectType<string>(v._id.toHexString());
13+
14+
doc._id = new bson.ObjectId('somehex');
15+
}
16+
17+
gh12537();

types/augmentations.d.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// this import is required so that types get merged instead of completely overwritten
2+
import 'bson';
3+
4+
declare module 'bson' {
5+
interface ObjectId {
6+
/** Mongoose automatically adds a conveniency "_id" getter on the base ObjectId class */
7+
_id: this;
8+
}
9+
}

types/index.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
/// <reference path="./validation.d.ts" />
2323
/// <reference path="./inferschematype.d.ts" />
2424
/// <reference path="./virtuals.d.ts" />
25+
/// <reference path="./augmentations.d.ts" />
2526

2627
declare class NativeDate extends global.Date { }
2728

types/types.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ declare module 'mongoose' {
8080
}
8181

8282
class ObjectId extends mongodb.ObjectId {
83-
_id: this;
83+
8484
}
8585

8686
class Subdocument<IdType = any> extends Document<IdType> {

0 commit comments

Comments
 (0)