Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to correctly type custom plugins? Also unable to register previously working plugins since v6.5.2 #12454

Closed
1 task done
rubek-joshi opened this issue Sep 21, 2022 · 1 comment · Fixed by #12486
Closed
1 task done
Labels
help wanted help This issue can likely be resolved in GitHub issues. No bug fixes, features, or docs necessary typescript Types or Types-test related issue / Pull Request
Milestone

Comments

@rubek-joshi
Copy link

Prerequisites

  • I have written a descriptive issue title

Mongoose version

6.6.1

Node.js version

16.14.0

MongoDB version

5.0.5

Operating system

Windows

Operating system version (i.e. 20.04, 11.3, 10)

11

Issue

My custom plugin used to be typed correctly up to version 6.5.1 where I'm basically following this guide. However, starting from v6.5.2 to the current v6.6.1, I get the following:
image

I was also unable to register the mongoose-unique-validator plugin and being shown the following error in my IDE:
image

I can't seem to find any info in the docs regarding how to correctly type my custom plugin nor am I sure if this is a bug or a breaking change.

@rubek-joshi rubek-joshi added help This issue can likely be resolved in GitHub issues. No bug fixes, features, or docs necessary help wanted labels Sep 21, 2022
@hasezoey hasezoey added the typescript Types or Types-test related issue / Pull Request label Sep 22, 2022
hasezoey added a commit to hasezoey/mongoose that referenced this issue Sep 22, 2022
@hasezoey
Copy link
Collaborator

Between 6.5.1 and 6.6.1 (the mentioned versions) the types for schema.plugin got more explicit than just any, but no generic case was added to test which broke existing plugins

current workaround is for the plugins to change their types from function pluginFunction(schema: Schema) to function pluginFunction(schema: Schema<any, any, any, any, any>)

i already tried to investigate and update the types, but i could not get it to work, the types always broke at The types returned by discriminator(...) are incompatible between these types (and i could not really update it, see #12457 and #12455)

see #12458 for reproduction

@vkarpov15 vkarpov15 added this to the 6.6.3 milestone Sep 27, 2022
vkarpov15 added a commit that referenced this issue Sep 29, 2022
vkarpov15 added a commit that referenced this issue Sep 30, 2022
fix(types): make schema.plugin() more flexible for schemas that don't define any generics
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted help This issue can likely be resolved in GitHub issues. No bug fixes, features, or docs necessary typescript Types or Types-test related issue / Pull Request
Projects
None yet
3 participants