Is it possible to be explicit on the first generic, but implicit (infer) the 2nd one?
for example a pick function:
function pick<T extends { [K: string]: any }, U extends keyof T>(obj: T, key: U): T[U] {
return obj[key];
}
interface Obj {
foo: string;
bar: string;
}
const obj = {
foo: 'foo',
bar: 'bar',
};
// works, available keys are inferred
pick(obj, 'bar');
// error: Expected 2 type arguments, but got 1.
// Is there a way I can tell to TS to infer the 2nd generic instead of expecting it explicitly?
pick<Obj>(obj, '');