I am trying to create an object with subobjects in typescript. I'm trying to set up a mongoose schema as shown in this question.
If I define the object and subobjects as interfaces, I'm not able to use them in a constant that I can set as a mongoose schema.
So is there a way for me to not have to type out the whole subobject twice, once in the interfaces and once in the constant?
export interface Pizza {
flavor: String;
size: String;
}
export interface Menu {
pizza: Pizza
}
// Doesn't work
export const Menu = {
store: String,
menu: Menu
}
// Works
export const Menu = {
store: String,
menu: {
pizza: {
flavor: String,
size: String
}
}
}
// What I really want
export const Menu = new mongoose.Schema({
store: String,
menu: Menu
});
// What I'm doing right now
export const Menu = new mongoose.Schema({
store: String,
menu: {
pizza: {
flavor: String,
size: String
}
}
});