Open MiguelsPizza opened 1 month ago
@MiguelsPizza could you clarify what you're referring to about the new type util?
sure! mongoose just added a Util type that is useful for sharing types between the frontend and backend. the new type:
JSONSerialized<T>
Represents what a document looks like when it is serialized for http. It converts ObjectIds to strings amongst other things.
This would be really nice for typescript mono-repos where you can generate usable types for the front end
btw @francescov1 how open are you to outside contributions? We ran into a couple of issues with type generation when we ran it on our code base which I have local fixes for.
The biggest one being collection names with '.'s in them don't generate valid types
for example collection called "Attachment.files" will generate the following type
//this is not a valid type
type Attachment.filesDocument = {...
I've just created a regex to remove the .'s from collection names. Is this something you would be willing to add in?
Oh that looks really nice, could completely remove the duplicate "mongoose-less" types that this library generates. I'll look into it when I have some time, thanks for mentioning it!
In terms of contributions I'm always open. There's so many edge cases with the ways people use Mongoose so the more help the better. Please go ahead and make a PR (with a unit test if possible) and I'll be happy to merge ASAP.
The new type-util is in mongoose 8.7.3