diff --git a/test/types/create.test.ts b/test/types/create.test.ts index 033010ae9b..983aafa0bd 100644 --- a/test/types/create.test.ts +++ b/test/types/create.test.ts @@ -40,6 +40,18 @@ Test.create([{ name: 'test' }], { validateBeforeSave: true }).then(docs => { expectType(docs[0].name); }); +Test.create({}).then(doc => { + expectType(doc.name); +}); + +Test.create([{}]).then(docs => { + expectType(docs[0].name); +}); + +expectError(Test.create({})); + +Test.create({ name: 'test' }); +Test.create({ _id: new Types.ObjectId('0'.repeat(24)), name: 'test' }); Test.insertMany({ name: 'test' }, {}, (err, docs) => { expectType(err); diff --git a/types/models.d.ts b/types/models.d.ts index 1a02fd8a20..5504ec91a5 100644 --- a/types/models.d.ts +++ b/types/models.d.ts @@ -192,12 +192,12 @@ declare module 'mongoose' { countDocuments(callback?: Callback): QueryWithHelpers, TQueryHelpers, T>; /** Creates a new document or documents */ - create>(docs: Array, options?: SaveOptions): Promise[]>; - create>(docs: Array, options?: SaveOptions, callback?: Callback>>): Promise[]>; - create>(docs: Array, callback: Callback>>): void; - create>(doc: DocContents | T): Promise>; - create>(...docs: Array): Promise[]>; - create>(doc: T | DocContents, callback: Callback>): void; + create>(docs: Array, options?: SaveOptions): Promise[]>; + create>(docs: Array, options?: SaveOptions, callback?: Callback>>): Promise[]>; + create>(docs: Array, callback: Callback>>): void; + create>(doc: DocContents): Promise>; + create>(...docs: Array): Promise[]>; + create>(doc: DocContents, callback: Callback>): void; /** * Create the collection for this model. By default, if no indexes are specified,