I have deeply nested objects like this (with more than 3 levels):
{
a1: 'foo1',
b1: [
{
c2: 'foo2',
d2: [
{
e3: 'foo3',
f3: 'foo3'
},
{
e3: 'bar3',
f3: 'bar3' }
]
}
]
};
and I've created nested interfaces like so:
export interface Level3 {
e3: string;
f3: string;
}
export interface Level2 {
c2: string;
d2: Level3[];
}
export interface Level1 {
a1: string;
b1: Level2[];
}
I'm transforming the most deeply nested object to something else, while leaving everything the upper structure untouched. For example:
export interface Level3Transformed {
e3Transformed: number[];
f3Transformed: number[];
}
export interface Level3 {
e3: string;
f3: string;
}
When I declare a Level1Transformed interface that is otherwise the same as Level1, but has Level3Transformed instead of Level3, is there any way to reuse all the in-between interfaces (like Level2)?
Or is there some other smart way to structure / declare similar nested objects like this while avoiding a lot of duplicate interfaces?
Edit: without using the OR operator?
interface level { [key: string]: string | Array<Level>}? And to answer is there any way to reuse, yes. You are already exporting interfaces. Just import them and use as required