Skip to content

Instantly share code, notes, and snippets.

@olibooty
Created October 6, 2023 15:59
Show Gist options
  • Select an option

  • Save olibooty/74d3b890bc5542e230b420d94bbddd1d to your computer and use it in GitHub Desktop.

Select an option

Save olibooty/74d3b890bc5542e230b420d94bbddd1d to your computer and use it in GitHub Desktop.
/**
*
* Selects elements from target object by provided keys
*/
export const pick = <T extends object, K extends keyof T = keyof T>(
object: T,
keys: K[]
): Pick<T, K> => {
let output: any = {};
for (const key of keys) {
if (key in object) {
output[key] = object[key];
}
}
return output;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment