Skip to content

Commit

Permalink
fix(index.d.ts): reorder create typings to allow array desctructuring
Browse files Browse the repository at this point in the history
  • Loading branch information
Ugzuzg committed Feb 2, 2021
1 parent 5c7d047 commit ccc0937
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
4 changes: 2 additions & 2 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<DocContents = T | DocumentDefinition<T>>(doc: DocContents): Promise<T>;
create<DocContents = T | DocumentDefinition<T>>(docs: DocContents[], options?: SaveOptions): Promise<T[]>;
create<DocContents = T | DocumentDefinition<T>>(doc: DocContents): 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<DocContents = T | DocumentDefinition<T>>(doc: DocContents, callback: (err: CallbackError, doc: T) => void): void;

/**
* Create the collection for this model. By default, if no indexes are specified,
Expand Down
9 changes: 8 additions & 1 deletion test/typescript/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,11 @@ Test.create({ name: 'test' }, { name: 'test2' }).then((docs: ITest[]) => console
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));

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

(async () => {
const [t1] = await Test.create([{ name: 'test' }]);
const [t2, t3, t4] = await Test.create({ name: 'test' }, { name: 'test' }, { name: 'test' });
(await Test.create([{ name: 'test' }]))[0];
(await Test.create({ name: 'test' }))._id;
})();

0 comments on commit ccc0937

Please sign in to comment.