Add extract
function
#308
aleclarson
started this conversation in
Ideas
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
A type-safe utility for extracting a value from a set of options. Returns
undefined
if the input value isn't in the set. Designed to work elegantly with the nullish coalescing operator (??
) for setting default values.Examples
Implementation
The function leverages TypeScript's type system to ensure type safety when working with literal types and unions. The return type handles cases where
TInput
is either fully contained within or partially overlaps withTOutput
.Beta Was this translation helpful? Give feedback.
All reactions