Skip to content

Commit

Permalink
types: add Model.insertOne() to types
Browse files Browse the repository at this point in the history
Re: #14843
  • Loading branch information
vkarpov15 committed Jan 6, 2025
1 parent 3203fe1 commit e519ac3
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
10 changes: 10 additions & 0 deletions test/types/models.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -988,3 +988,13 @@ async function gh14802() {
const conn2 = mongoose.createConnection('mongodb://127.0.0.1:27017/mongoose_test');
Model.useConnection(conn2);
}

async function gh14843() {
const schema = new mongoose.Schema({
name: String
});
const Model = model('Test', schema);

const doc = await Model.insertOne({ name: 'taco' });
expectType<ReturnType<(typeof Model)['hydrate']>>(doc);
}
2 changes: 2 additions & 0 deletions types/models.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -576,6 +576,8 @@ declare module 'mongoose' {
Array<MergeType<THydratedDocumentType, Omit<DocContents, '_id'>>>
>;

insertOne<DocContents = AnyKeys<TRawDocType>>(doc: DocContents | TRawDocType, options?: SaveOptions): Promise<THydratedDocumentType>;

/**
* List all [Atlas search indexes](https://www.mongodb.com/docs/atlas/atlas-search/create-index/) on this model's collection.
* This function only works when connected to MongoDB Atlas.
Expand Down

0 comments on commit e519ac3

Please sign in to comment.