Skip to content

Commit

Permalink
fix(index.d.ts): improve autocomplete for new Model() by making `do…
Browse files Browse the repository at this point in the history
…c` an object with correct keys

Fix #10475
Re: #10343
Re: #10302
  • Loading branch information
vkarpov15 committed Jul 28, 2021
1 parent 2066180 commit 060039d
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -750,12 +750,13 @@ declare module 'mongoose' {
discriminator<T, U extends Model<T>>(name: string | number, schema: Schema<T, U>, value?: string | number | ObjectId): U;
}

type AnyKeys<T> = Partial<{ [P in keyof T]: T[P] | any }>;
interface AnyObject { [k: string]: any }
type EnforceDocument<T, TMethods> = T extends Document ? T : T & Document<any, any, T> & TMethods;

export const Model: Model<any>;
interface Model<T, TQueryHelpers = {}, TMethods = {}> extends NodeJS.EventEmitter, AcceptsDiscriminator {
new(doc?: T | any): EnforceDocument<T, TMethods>;
new(doc?: AnyKeys<T> & AnyObject): EnforceDocument<T, TMethods>;

aggregate<R = any>(pipeline?: any[]): Aggregate<Array<R>>;
aggregate<R = any>(pipeline: any[], cb: Function): Promise<Array<R>>;
Expand Down

0 comments on commit 060039d

Please sign in to comment.