Can't seem to type my functions correctly (using discriminator models) #14273
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
Prerequisites
Mongoose version
6.12.5
Node.js version
18.19.0
MongoDB version
5.0
Operating system
macOS
Operating system version (i.e. 20.04, 11.3, 10)
Sonoma 14.2.1
Issue
There are a number of situations where I seem to fail in writing the correct typing to make the typescript code work.
I've defined my models as follow
The following works without issues:
When moving the generic typing to the class definition it doesn't work, the code:
Displays an error on the last function call's argument (testClass2.testFunction(DiscriminatedModel);
TS2345 - Argument of type Model<IDiscriminator..... is not assignable to type Model<IBase......
But I don't seem to understand why moving the generic triggers the error since (to me) it looks like it hasn't changed the inference between the 2 ways of writing the code.
The text was updated successfully, but these errors were encountered: