Currently, I am working on a function that requires only one of the configurations specified in the SubNodeConfig
interface. While I can set all of them as optional as shown below, I am looking for a way to make one of them mandatory, possibly using the non-null assertion operator !
.
export interface SubNodeConfig {
alphaConfig?: AlphaConfig;
betaConfig?: BetaConfig;
charlieConfig?: CharlieConfig;
deltaConfig?: DeltaConfig;
}
export interface MainNode {
id: number;
config: SubNodeConfig;
}
This function is intended to be used in the following context:
const getUpdated = (
originalNodes: MainNode[],
updatedConfig: SubNodeConfig
) => {
const updatedNodes= [...originalNodes];
updatedNodes[indexOfNodeToUpdate] = {
id: 123456,
config: updatedConfig,
};
return updatedNodes;
};
I have also referred to the TypeScript utility docs, but I might have overlooked something. Thank you for your help.