Looking at this answer, a working solution could be:
interface Foo {
nested: {
wanted: string,
unwanted: string
}
}
interface Bar {
foos: Array<Foo>
}
type Modify<T, R> = Omit<T, keyof R> & R;
type FoosWithoutUnwanted = Modify<Foo, {
nested: {
wanted: string
}
}>
type Works = Modify<Bar, {
foos: Array<FoosWithoutUnwanted>
}>
Even if this works, I think that declaring different Interfaces would be a better approach:
interface Nested {
wanted: string;
}
interface NestedWithUnwanted extends Nested {
unwanted: string;
}
interface Foo {
nested: Nested
}
interface FooWithUnwanted {
nested: NestedWithUnwanted
}
interface Bar {
foos: Array<Foo>;
}
interface BarWithUnwanted {
foos: Array<FooWithUnwanted>;
}