Imagine we have a base interface named Foo
:
interface Foo {
a: string;
b: {
c: string;
}
}
Now, I wish to create a child interface called FooChild
, which extends Foo
by adding a new field d: string
nested inside the existing b
field.
interface FooChild extends Foo {
a: string;
b: {
c: string;
d: string;
}
}
Is there any way to define FooChild
more succinctly without explicitly mentioning the existing fields like a
and c
? For example:
interface FooChild extends Foo {
// a: string; // this is fine
b: {
// c: string; // encountering an issue - Property c is missing...
d: string;
}
}
While omitting individual fields may work if you only have one field in b
, it becomes cumbersome when dealing with a large number of fields. The repetitive nature of having to list all existing fields just to add a single new one can lead to code duplication.