francescov1 / mongoose-tsgen

A plug-n-play Typescript generator for Mongoose.
105 stars 24 forks source link

How do I get id (not _id) in the generated schema for --no-mongoose #129

Closed akshay-nm closed 10 months ago

akshay-nm commented 10 months ago

I want to use id instead of _id in frontend. I am using mongoose-tsgen for types. I love the project but it restricts me to stick to _id.

francescov1 commented 10 months ago

Hi @akshay-nm, sorry you can't use the --no-mongoose flag in this case, otherwise the generated types would not properly reflect MongoDB documents.

As a workaround, you can use the following helper type:

type WithId<T> = T & { id: string };

// Example
type UserWithId = WithId<User>

Closing for now, but feel free to re-open if you have any questions or suggestions for a feature