I am looking to create a function
that will take a string
as its first argument and will only accept a second argument of type object
if it contains the first argument as a key with a boolean
value:
const checkFlag = (str:string, obj) => obj[str]
Although this approach works, it is not ideal (having the generic object as the first argument):
const checkFlag = <K extends {[key:string]:boolean}, T extends keyof K>(str:T, obj:K) => obj[str]
resulting in Type Errors like the following: https://i.sstatic.net/l1VNA.png
https://i.sstatic.net/zcNWz.png
What type annotations can I use to resolve this issue?