Skip to content

Commit

Permalink
fix(types): make schema.plugin() more flexible for schemas that don't…
Browse files Browse the repository at this point in the history
… define any generics

Fix #12454
Re: #12139
  • Loading branch information
vkarpov15 committed Sep 29, 2022
1 parent cb186cc commit 1d618df
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
7 changes: 7 additions & 0 deletions test/types/plugin.test.ts
Expand Up @@ -59,10 +59,17 @@ const testSchema = new Schema<Test, TestModel, TestInstanceMethods, TestQueryHel
lastName: { type: String, required: true }
});

function pluginGeneric(schema: Schema): void {
schema.static('test', function() {
return 0;
});
}

testSchema.plugin(pluginVirtuals);
testSchema.plugin(pluginQueryHelpers);
testSchema.plugin(pluginMethods);
testSchema.plugin(pluginStatics);
testSchema.plugin(pluginGeneric);

const Foo = connection.model<Test, TestModel, TestQueryHelpers>('Test', testSchema);

Expand Down
2 changes: 1 addition & 1 deletion types/index.d.ts
Expand Up @@ -264,7 +264,7 @@ declare module 'mongoose' {
pathType(path: string): string;

/** Registers a plugin for this schema. */
plugin<PFunc extends PluginFunction<DocType, M, TInstanceMethods, TQueryHelpers, TVirtuals, TStaticMethods>, POptions extends Parameters<PFunc>[1] = Parameters<PFunc>[1]>(fn: PFunc, opts?: POptions): this;
plugin<PFunc extends PluginFunction<any, any, any, any, any, any>, POptions extends Parameters<PFunc>[1] = Parameters<PFunc>[1]>(fn: PFunc, opts?: POptions): this;

/** Defines a post hook for the model. */
post<T = HydratedDocument<DocType, TInstanceMethods>>(method: MongooseDocumentMiddleware | MongooseDocumentMiddleware[] | RegExp, fn: PostMiddlewareFunction<T, T>): this;
Expand Down

0 comments on commit 1d618df

Please sign in to comment.