Skip to content

Commit

Permalink
backport pull 13515
Browse files Browse the repository at this point in the history
  • Loading branch information
IslandRhythms committed Aug 11, 2023
1 parent d4a1080 commit 0ae1367
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 4 deletions.
6 changes: 3 additions & 3 deletions package.json
Expand Up @@ -50,6 +50,7 @@
"eslint-plugin-markdown": "^3.0.0",
"eslint-plugin-mocha-no-only": "1.1.1",
"express": "^4.18.1",
"fs-extra": "~11.1.1",
"highlight.js": "11.7.0",
"lodash.isequal": "4.5.0",
"lodash.isequalwith": "4.4.0",
Expand All @@ -64,11 +65,10 @@
"q": "1.5.1",
"sinon": "15.0.1",
"stream-browserify": "3.0.0",
"tsd": "0.25.0",
"tsd": "^0.25.0",
"typescript": "4.9.5",
"uuid": "9.0.0",
"webpack": "5.75.0",
"fs-extra": "~11.1.1"
"webpack": "5.75.0"
},
"directories": {
"lib": "./lib/mongoose"
Expand Down
19 changes: 19 additions & 0 deletions test/types/mongo.test.ts
@@ -0,0 +1,19 @@
import * as mongoose from 'mongoose';
import { expectType } from 'tsd';
import * as bson from 'bson';

import GridFSBucket = mongoose.mongo.GridFSBucket;

function gh12537() {
const schema = new mongoose.Schema({ test: String });
const model = mongoose.model('Test', schema);

const doc = new model({});

const v = new bson.ObjectId('somehex');
expectType<string>(v._id.toHexString());

doc._id = new bson.ObjectId('somehex');
}

gh12537();

Check warning on line 19 in test/types/mongo.test.ts

View workflow job for this annotation

GitHub Actions / Lint TS-Files

Newline required at end of file but not found
9 changes: 9 additions & 0 deletions types/augmentations.d.ts
@@ -0,0 +1,9 @@
// this import is required so that types get merged instead of completely overwritten
import 'bson';

declare module 'bson' {
interface ObjectId {
/** Mongoose automatically adds a conveniency "_id" getter on the base ObjectId class */
_id: this;
}
}

Check warning on line 9 in types/augmentations.d.ts

View workflow job for this annotation

GitHub Actions / Lint TS-Files

Newline required at end of file but not found
1 change: 1 addition & 0 deletions types/index.d.ts
Expand Up @@ -22,6 +22,7 @@
/// <reference path="./validation.d.ts" />
/// <reference path="./inferschematype.d.ts" />
/// <reference path="./virtuals.d.ts" />
/// <reference path="./augmentations.d.ts" />

declare class NativeDate extends global.Date { }

Expand Down
2 changes: 1 addition & 1 deletion types/types.d.ts
Expand Up @@ -80,7 +80,7 @@ declare module 'mongoose' {
}

class ObjectId extends mongodb.ObjectId {
_id: this;

}

class Subdocument<IdType = any> extends Document<IdType> {
Expand Down

0 comments on commit 0ae1367

Please sign in to comment.