types(plugin): allow passing model with custom TStatics into Schema.prototype.plugin()#16090
Open
types(plugin): allow passing model with custom TStatics into Schema.prototype.plugin()#16090
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This pull request updates Mongoose’s TypeScript typings to make Schema#plugin() accept plugins whose schema parameter is typed as a generic Schema even when the schema’s model type includes custom statics.
Changes:
- Add a fallback overload for
Schema#plugin()that uses a baseModel<DocType, ...>model type. - Add a TypeScript type test that reproduces and validates the intended
schema.plugin(plugin)behavior for a schema with a custom model interface.
Reviewed changes
Copilot reviewed 1 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| types/index.d.ts | Adds an additional Schema#plugin() overload to improve plugin compatibility with schemas using custom model typings. |
| test/types/plugin.test.ts | Adds a compile-time type test case (gh16086) covering the new overload scenario. |
AbdelrahmanHafez
approved these changes
Mar 12, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fix #16086
Summary
Added a wider
plugin()function that lets you pass in a plugin that operates on any schema.Examples