Created
November 27, 2020 21:15
-
-
Save exuanbo/e9fdc9a30d3c1c1e1338e5b4629c1f6f to your computer and use it in GitHub Desktop.
This file contains 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 const unwrap = <T>( | |
value: T | undefined | null, | |
errorMessage?: string | |
): T | never => { | |
if (value === null || value === undefined) { | |
throw new Error(errorMessage ?? 'Missing value') | |
} | |
return value | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment