Skip to content

Commit

Permalink
fix(index.d.ts): make Model.create() with a spread return a promise…
Browse files Browse the repository at this point in the history
… of array rather than single doc

Fix #9817
  • Loading branch information
vkarpov15 committed Jan 19, 2021
1 parent 60a32c3 commit bc2395e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
10 changes: 5 additions & 5 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -630,11 +630,11 @@ declare module 'mongoose' {
countDocuments(filter: FilterQuery<T>, callback?: (err: any, count: number) => void): Query<number, T>;

/** Creates a new document or documents */
create<Z = T | DocumentDefinition<T>>(doc: Z): Promise<T>;
create<Z = T | DocumentDefinition<T>>(docs: Array<Z>, options?: SaveOptions): Promise<Array<T>>;
create<Z = T | DocumentDefinition<T>>(...docs: Array<Z>): Promise<T>;
create<Z = T | DocumentDefinition<T>>(doc: Z, callback: (err: CallbackError, doc: T) => void): void;
create<Z = T | DocumentDefinition<T>>(docs: Array<Z>, callback: (err: CallbackError, docs: Array<T>) => void): void;
create<DocContents = T | DocumentDefinition<T>>(doc: DocContents): Promise<T>;
create<DocContents = T | DocumentDefinition<T>>(docs: DocContents[], options?: SaveOptions): Promise<T[]>;
create<DocContents = T | DocumentDefinition<T>>(...docs: DocContents[]): Promise<T[]>;
create<DocContents = T | DocumentDefinition<T>>(doc: DocContents, callback: (err: CallbackError, doc: T) => void): void;
create<DocContents = T | DocumentDefinition<T>>(docs: DocContents[], callback: (err: CallbackError, docs: T[]) => void): void;

/**
* Create the collection for this model. By default, if no indexes are specified,
Expand Down
2 changes: 1 addition & 1 deletion test/typescript/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Test.create({ _id: '0'.repeat(24), name: 'test' }).then((doc: ITest) => console.

Test.create([{ name: 'test' }], { validateBeforeSave: false }).then((docs: ITest[]) => console.log(docs[0].name));

Test.create({ name: 'test' }, { name: 'test2' }).then((doc: ITest) => console.log(doc.name));
Test.create({ name: 'test' }, { name: 'test2' }).then((docs: ITest[]) => console.log(docs[0].name));

Test.insertMany({ name: 'test' }).then((doc: ITest) => console.log(doc.name));
Test.insertMany([{ name: 'test' }], { session: null }).then((docs: ITest[]) => console.log(docs[0].name));
Expand Down

0 comments on commit bc2395e

Please sign in to comment.