Created
February 6, 2024 17:53
-
-
Save kirpalmakanga/72e7c4535babb86ac4603c295d432acd to your computer and use it in GitHub Desktop.
Type-safe pick function
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export function pick<T extends object, K extends keyof T>( | |
base: T, | |
...keys: K[] | |
): Pick<T, K> { | |
if (!keys.length) return base; | |
const entries = keys.map((key) => [key, base[key]]); | |
return Object.fromEntries(entries); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment