Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature Request] Add JSONSerialized type to generated output #164

Open
MiguelsPizza opened this issue Oct 30, 2024 · 4 comments
Open

[Feature Request] Add JSONSerialized type to generated output #164

MiguelsPizza opened this issue Oct 30, 2024 · 4 comments

Comments

@MiguelsPizza
Copy link

The new type-util is in mongoose 8.7.3

@francescov1
Copy link
Owner

@MiguelsPizza could you clarify what you're referring to about the new type util?

@MiguelsPizza
Copy link
Author

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

The code

@MiguelsPizza
Copy link
Author

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?

@francescov1
Copy link
Owner

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants