function extractStringValue<T extends object, S extends keyof PickByValue<T, string>>(
obj: T,
key: S
): string {
return obj[key];
};
The PickByValue function extracts properties of object T with values of type string.
type CustomType = {
propStr: string;
propNum: number;
}
type Foo = PickByValue<CustomType, string>;
// Foo = {
// propStr: string;
// }
How can we modify PickByValue to avoid errors in the above code?
We aim to access a property of type string from obj
in a function.