I have key-value pairs that 'come in pairs'. In other words, if I have one key-value pair A:B then I also want to require my object to have C:D, but it can also have neither pair. (Think message:string for one pair and min-length:number for the other pair.) Is there an elegant way to make an interface made up of an arbitrary number of such pairs?
Edit: For clarification, I want to design an interface for objects where these would be allowed:
{
//First pair
message1: string;
minLength1: number;
//Second pair
message2: string;
minLength2: number;
// ...
}
{
//First pair omitted altogether
//Just the second pair
message2: string;
minLength2: number;
}
... but where objects like the following are NOT allowed because you only have one half of a pair:
{
//First pair
message1: string;
// minLength1: number; // Error †
// ...
}
† Error: if message1 is included then you must also include minLength1