I want to create an object using default values for an interface, but at the same time changing the structure of the object. For example, for this interface:
interface IPerson {
name: string
age: number
}
I want to create an object like this:
const person: IPerson = {
name: {
type: String,
required: true
},
age: {
type: Number,
required: true
}
}
The only way I found is to add the type for the object to name and age of
the IPerson interface, like so:
interface IPerson {
name: string | IProp
age: number | IProp
}
interface IProp {
type: any
required?: boolean
// ...
}
I do not want to change the original interface IPerson though. So I was
thinking of something like this:
const person: IProperties<IPerson> = {
// use properties of IPerson to determine which key/value pairs are valid in this object
}