Skip to content

types(plugin): allow passing model with custom TStatics into Schema.prototype.plugin()#16090

Open
vkarpov15 wants to merge 2 commits intomasterfrom
vkarpov15/gh-16086
Open

types(plugin): allow passing model with custom TStatics into Schema.prototype.plugin()#16090
vkarpov15 wants to merge 2 commits intomasterfrom
vkarpov15/gh-16086

Conversation

@vkarpov15
Copy link
Collaborator

Fix #16086

Summary

Added a wider plugin() function that lets you pass in a plugin that operates on any schema.

Examples

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 base Model<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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Schema.plugin() rejects (schema: Schema) => void when Model type has custom statics

3 participants