Here is a snippet of my code:
const fn1 = (param1: string, param2: string, param3: string): Promise<void> => {return new Promise()}
const fn2 = (param1: string, param2: string): void => {return}
const options = {
option1: fn1,
option2: fn2,
option3: fn1,
option4: fn2,
}
const myOption = 'option1';
const myParam1 = 'a';
const myParam2 = 'b';
const myParam3 = 'c';
options[myOption](myParam1, myParam2, myParam3); // ERROR in this line
I started with Javascript but then had to switch to TypeScript. The linter doesn't report any issues, however when I try to run it using ts-node, an error is displayed:
Element implicitly has an 'any' type because expression of type 'string' can't be used to index type...[the type object here]
How do I properly type the object so that I can call the functions inside without resorting to a switch/case or endless else/if statements?