Skip to content

Return-Types for Schema.prototype.discriminator do not align with runtime behavior #12457

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

Closed
2 tasks done
hasezoey opened this issue Sep 22, 2022 · 0 comments · Fixed by #12522
Closed
2 tasks done

Return-Types for Schema.prototype.discriminator do not align with runtime behavior #12457

hasezoey opened this issue Sep 22, 2022 · 0 comments · Fixed by #12522
Labels
typescript Types or Types-test related issue / Pull Request
Milestone

Comments

@hasezoey
Copy link
Collaborator

Prerequisites

  • I have written a descriptive issue title
  • I have searched existing issues to ensure the issue has not already been raised

Issue

Currently Schema.prototype.discriminator takes the discriminator schema as a argument (argument number 2 of 2) and this is the parent schema the discriminator schema is applied on and returns this at the end.
But the types currently imply that this function returns the discriminator schema (the schema from the argument):

Runtime:

mongoose/lib/schema.js

Lines 528 to 532 in 4495cf3

Schema.prototype.discriminator = function(name, schema) {
this._applyDiscriminators = Object.assign(this._applyDiscriminators || {}, { [name]: schema });
return this;
};

Types:

discriminator<T = Schema>(name: string, schema: T): DiscriminatorSchema<DocType, M, TInstanceMethods, TQueryHelpers, TVirtuals, T>;

@hasezoey hasezoey added the typescript Types or Types-test related issue / Pull Request label Sep 22, 2022
@vkarpov15 vkarpov15 added this to the 6.6.5 milestone Sep 30, 2022
vkarpov15 added a commit that referenced this issue Oct 5, 2022

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
fix(types): indicate that Schema.prototype.discriminator() returns `this`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
typescript Types or Types-test related issue / Pull Request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants