I'm new to TypeScript and am trying to access the property of an object by a string. Here is a sandbox showing my problem: https://codesandbox.io/s/optimistic-mendel-f1zdg?file=/src/App.tsx
Code snippet (App.tsx: 17): newFlags[event.target.name] = event.target.value;
Error: Element implicitly has an 'any' type because expression of type 'string' can't be used to index type '{ hidden: string; completed: string; }'.
I can make the error go away by adding an if statement like if(event.target.name === hidden || event.target.name === "completed") but that solution seems really hard to scale. It seems great if I could use the <Flag> type as a variable, but that seems to make TypeScript mad.
Is there a DRY solution to fixing this error?