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

TypeScript returns an error if you run a query on a subclass field of a model #14842

Closed
2 tasks done
nikzanda opened this issue Aug 29, 2024 · 2 comments
Closed
2 tasks done
Labels
typescript Types or Types-test related issue / Pull Request
Milestone

Comments

@nikzanda
Copy link

Prerequisites

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

Mongoose version

8.6.0

Node.js version

20.10.0

MongoDB server version

6.0.2

Typescript version (if applicable)

5.5.4

Description

First of all, I find the new feature introduced by the minor release 8.6.0 very useful, which checks if fields exist in the main interface of the model when running queries! It’s a great idea!

However, I encountered a problem with models and subclasses: before 8.6.0, it was possible to run a query on a subclass field from the main model, but now TypeScript reports an error (solved old issue).

interfaces:
image
image
image

query:
Screenshot 2024-08-29 at 11 49 20
Screenshot 2024-08-29 at 11 49 33

Steps to Reproduce

Reproduction link: https://stackblitz.com/edit/vitejs-vite-jkwelc?file=src%2Findex.ts

Expected Behavior

Although the main interface does not include the fields of the subclasses, you should still be able to run a query from the main model, as it worked prior to version 8.6.0.

@vkarpov15 vkarpov15 added this to the 8.6.1 milestone Aug 29, 2024
@vkarpov15 vkarpov15 added the has repro script There is a repro script, the Mongoose devs need to confirm that it reproduces the issue label Aug 29, 2024
@vkarpov15 vkarpov15 modified the milestones: 8.6.1, 8.6.2 Sep 3, 2024
@vkarpov15
Copy link
Collaborator

This issue will be fixed by #14874 .

This is another good point for #14874 re: #14764: Mongoose does support automatically inferring discriminator schema if discriminator key is set in the query filter. So if we implement #14764, we would need to come up with a way to support that.

@vkarpov15 vkarpov15 added typescript Types or Types-test related issue / Pull Request and removed has repro script There is a repro script, the Mongoose devs need to confirm that it reproduces the issue labels Sep 10, 2024
@vkarpov15
Copy link
Collaborator

Fixed by #14874

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

No branches or pull requests

2 participants