forked from Automattic/mongoose
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
types: augment bson.ObjectId instead of adding on own type
fixes Automattic#12537
- Loading branch information
Showing
4 changed files
with
23 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,17 @@ | ||
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'); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
// the import below is said to be unused, but actually required so that types get merged and not overwritten | ||
import * as bson from 'bson'; | ||
|
||
declare module 'bson' { | ||
interface ObjectId { | ||
/** Mongoose automatically adds a conveniency "_id" getter on the base ObjectId class */ | ||
_id: this; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters