const func = <T extends object, S extends keyof PickByValue<T, string>>(
obj: T,
key: S
): string => {
return obj[key];
};
PickByValue extracts the properties of T whose values are of type string.
type T = {
propStr: string;
propNum: number;
}
type Bar = PickByValue<T, string>;
// Bar = {
// propStr: string;
// }
Is it possible to create a PickByValue such that the above code does not result in an error?
What we want to do is to use a property of type string within obj
in a function.