Deduced type of an array in a schema is plain array instead of mongoose array. #14983
Open
1 task done
Labels
Milestone
Prerequisites
Mongoose version
8.6.2
Node.js version
20.18.0
MongoDB version
7.0.14
Operating system
Windows
Operating system version (i.e. 20.04, 11.3, 10)
10.0.22631
Issue
Here is simple example of schema in mongoose:
this
object in a methods is a hydrated document, however array deduced not as mongoose array but as plain array instead. Example demonstrates this issue by trying to useaddToSet
method of a mongoose array, but getting type error.Same issue can be depicted with this example:
I have pretty vague understanding of how schemas in typescript should be properly defined, I've read that we can provide interfaces ourselves by using template parameters of
model
andSchema
however it essentially produces a duplication in a boilerplate types and defies already defined principles of deduction established withHydratedDocumentFromSchema
,InferSchemaType
and other typescript helper functions.The text was updated successfully, but these errors were encountered: