typegoose
typegoose copied to clipboard
Change `Ref` type to transparently use `DocumentType`
Describe what you need | want
Currently Ref<Class, Type> only passes the first generic (Class) directly through to the mongoose PopulatedDoc, which is not really great and also not the correct types
Do you have already an idea for the implementation?
change Ref from the following:
= mongoose.PopulatedDoc<PopulatedType, RawId>
to be
= mongoose.PopulatedDoc<DocumentType<PopulatedType>, RawId>
this change could potentially be breaking, so it is put off until a next major typegoose version
PS: this change would require changing isDocument typeguard to add | unknown to the first parameter as the allowed value to preserve being able to pass anything into it
This change would also likely modify the Ref type directly by removing the | undefined possibility from the type directly
https://github.com/typegoose/typegoose/blob/2f001e4acb9f1ce4eca49d41a3b483e2184f1013/src/types.ts#L380
also to maybe consider is changing the fallback case of when _id is not explicitly defined in a class for DocumentType to fallback to ObjectId instead of any
this currently cannot be changed because typeguards expect ref but cannot narrow down the first parameter and so allow too much stuff
https://github.com/typegoose/typegoose/blob/2f001e4acb9f1ce4eca49d41a3b483e2184f1013/src/types.ts#L16
:tada: This issue has been resolved in version 10.0.0-beta.1 :tada:
The release is available on:
Your semantic-release bot :package::rocket:
:tada: This issue has been resolved in version 10.0.0 :tada:
The release is available on:
This was added manually, because semantic-release hit a rate-limit and cannot be re-triggered