I'm a fan of Open Source and have a growing interest in serverless and edge computing. I'm not a big fan of spiders, but they're doing good work eating bugs. I also stream on Twitch.
I'm a fan of Open Source and have a growing interest in serverless and edge computing. I'm not a big fan of spiders, but they're doing good work eating bugs. I also stream on Twitch.
interfaceBaseEntity{id:string;createdAt:Date;}typeEntity<T>=T&BaseEntity;interfaceVehicle{model:string;year?:string;seatsCount?:number;}// Enforce having the bare minimum entity propertiestypeMongooseDocument<TextendsBaseEntity>=T&mongoose.Document;constdbDocument:MongooseDocument<Entity<Vehicle>>={SomeMongooseDocProperty:"yolo",createdAt:newDate(),id:"5FCA1C32-1D92-47CA-A885-A5A747E6E4FB",model:"Mini",seatsCount:4,year:"1999"};
From there you could even do a Mongoose document generic type.
You could refine this more if you wanted to make a Vehicle type which just wraps the
Entity<T>
.You can see it in action in the enhanced TypeScript playground.
Also, this might interest you.
An Enhanced TypeScript Playground
Nick Taylor
Ok, I will play with it. Thank you.
You can even go a bit further.
See the updated playground example