TypeScript solution:
function pick(
obj: T,
paths: Array
): Pick {
const ret = Object.create(null);
for (const k of paths) {
ret[k] = obj[k];
}
return ret;
}
The typing information even allows for auto-completion:
Credit to DefinitelyTyped for U extends keyof T
trick!
TypeScript Playground