The interface I'm working with is structured as follows:
export interface InterfaceA {
propA?: any;
}
export interface MyBaseInterface extends InterfaceA {
propA?: {
nestedPropA?: {
nestedNestedPropA: string;
nestedNestedPropB: string;
};
};
};
My goal is to extend MyBaseInterface while inheriting all its properties and adding additional ones. The desired outcome should look like this:
export interface MyNewInterface {
propA?: {
nestedPropA?: {
nestedNestedPropA: string;
nestedNestedPropB: string;
nestedNestedPropC: string;
};
};
};
I attempted a few approaches based on this reference question. For example:
export interface MyNewInterface extends MyBaseInterface {
propA?: MyBaseInterface['propA'] & {
nestedPropA?: MyBaseInterface['propA']['nestedPropA'] & {
nestedNestedPropC: string;
};
};
};
However, I encountered an issue where "MyBaseInterface does not have nestedPropA" error occurred due to it being optional. Making the props mandatory would not allow for overriding them. Using extends Required<>
would enforce implementing unwanted properties.
If anyone can provide guidance or assistance, it would be greatly appreciated. Thank you.