[TS] model, new Model, Document and HydratedDocument: DocType typing inconsistencies #12573
Closed
1 task done
Labels
typescript
Types or Types-test related issue / Pull Request
Milestone
Prerequisites
Mongoose version
6.6.5
Node.js version
16.18.0
MongoDB server version
6.0
Typescript version (if applicable)
4.8.4
Description
This issue is possibly related to #10302
We are migrating from v5 to v6 and the situation in v6 is weirder than in v5.
It seems to me (in my really humble opinion) that
DocType
is not working as expected both when specifying what we pass tonew MyModel
but also when trying to tell us what comes back from model.I think that the main issue is that
DocType
is only used to tell theDocument
what it should accept in some methods or the lean shape it returns, while it isHydratedDocument
that merges the definition ofDocType
andDocument
, leaving some edge cases on howHydratedDocument
handles it'sDocType
and how it is handled when callingnew MyModel()
Steps to Reproduce
OK:
KO:
Expected Behavior
I would expect
const MyModel = model<any>('My', MySchema); const myDocument = new MyModel({ ... })
to behave likeHydratedDocument<any>
.I would expect
const MyModel = model<any>('My'); const myDocument = new MyModel({ ... })
to behave likeHydratedDocument<any>
.I would expect
const myDocument = new MyModel<any>({ field: 'a' })
to behave likeHydratedDocument<any>
.The text was updated successfully, but these errors were encountered: