I'd like to define the following function:
getStringValidation<FormValues>("name")
and have the following constraints:
FormValuesis an object that contains the"name"key (or whatever the argument is)- The value that corresponds to this key in the object should be of type
string.
For example:
Allowed
getStringValidation<{ name: string, age: number }>("name")
Should error
getStringValidation<{ name: string, age: number }>("age") // the value is of type number
getStringValidation<{ name: string, age: number }>("address") // the key doesn't exist in the object
How could I achieve this?