It seems like a simple task, but I'm having trouble finding the right configuration. My goal is to create a type for an array where each index corresponds to the "plugin" value provided (an enum) and maps to the types of options specific to that plugin. Here's an example:
enum Plugins {
A = "A",
B = "B",
...
};
const allOptions = [
{
plugin: Plugins.A,
options: {
// miscellaneous, unique options for Plugin A
}
},
{
plugin: Plugins.B,
options: {
// miscellaneous, unique options for Plugin B
}
},
...
]
- Each plugin would have its own custom type for its unique options,
- The array could be of any length and plugins could be added in any order,
- There could be multiple entries for a single plugin.
The goal is for TypeScript to recognize whatever plugin the user provides for the "plugin" property in the array, and then validate that the options for that array index are of the correct type.
I've looked into TypeScript's conditional types documentation, but it doesn't seem to fully apply in this case.