I am unsure if the term sub interface
is correct, but my goal is to develop an interface that inherits all properties from the super interface except for some optional ones. Despite referring to the TypeScript documentation for interfaces, I was unable to locate the necessary information.
I understand that I could achieve this by manually copying and excluding certain props from the super Interface
, however, I am not fond of this approach as it revolves around wrapping a function that necessitates an argument of type T
, while also eliminating specific optional properties before passing them on. To simplify, I will provide a basic example below.
interface DefaultParams {
param1: boolean;
param2: boolean;
param3?: boolean;
... // along with numerous other properties sourced from the library that I intend to include
}
// note the absence of 'param3' within the SubParams interface
interface SubParams {
param1: boolean;
param2: boolean;
... // and various other properties derived from the library that I wish to retain
}
type InnerFunction = (params: DefaultParams) => void;
const funcToCall: InnerFunction = thirdPartyLibrary.function;
function wrapperFunction(params: SubParams) {
funcToCall(params);
}
In essence, my objective is to establish a SubParams
interface that seamlessly aligns with DefaultParams
, excluding the param3
optional property.
This marks my inaugural query on Stackoverflow, any corrections or additions are greatly appreciated.