When working with a list of operations in a database, each operation may have a unique set of variables that need to be passed. To make adding new operations easier, I decided to store the interfaces within a list structure like this:
const operation = {
add: 'example',
list: 'example2',
};
interface operationVariable {
add: { asset: string };
}
The goal is to access the correct interface for each operation from the list using a function like this:
function graphql<OP = keyof typeof operation>(request: OP, variables: operationVariable[OP], server = CONFIG.GRAPHQLSERVER) {
return post(server, request);
}
However, an error message stating:
Type 'OP' cannot be used to index type 'operationVariable'.
Even if the 'list' operation is removed, the error persists. How can TypeScript be configured to behave according to my intentions?