I have interface with list of optional properties.
export interface OptionalIds {
entityA_Id?: number;
entityB_Id?: number;
entityC_Id?: number;
}
And I have a requirement that EXACTLY one of them MUST be defined. Something like that:
export interface RequiredBId {
entityA_Id?: undefined;
entityB_Id: number;
entityC_Id?: undefined;
}
export interface RequiredCId {
entityA_Id?: undefined;
entityB_Id?: undefined;
entityC_Id: number;
}
export interface OptionalIds {
entityA_Id?: number;
entityB_Id?: number;
entityC_Id?: number;
}
export type RestrictedOptionalIds = OptionalIds & (RequiredAId | RequiredBId | RequiredCId)
The question is: Is there other way to achieve described behaviour without weird constructions?
Updated Answer
Thanks to this post for
RequireOnlyOne: https://stackoverflow.com/a/49725198/4529555Original Answer
Thanks to this post for
RequireAtLeastOne: https://stackoverflow.com/a/49725198/4529555