How should I define interfaces of documents when using Typescript and Mongodb?
You can try to separate them in a smart way :
interface User { username: string; password: string; somethingElse: string;}export interface UserJSON extends User { _id : string}export interface UserDB extends User { _id : mongodb.ObjectId}
and later take either UserJSON ( client ) or UserDB ( server-side ).
Thanks to @drinchev. And I have figured out a better way to do it, using generics:
interface User<IdType> { _id: IdType; username: string; posts: Post<IdType>[];}interface Post<IdType> { _id: IdType; text: string;}export type UserDB = User<mongodb.ObjectID>;