Skip to content

Instantly share code, notes, and snippets.

@exuanbo
Created November 27, 2020 21:15
Show Gist options
  • Save exuanbo/e9fdc9a30d3c1c1e1338e5b4629c1f6f to your computer and use it in GitHub Desktop.
Save exuanbo/e9fdc9a30d3c1c1e1338e5b4629c1f6f to your computer and use it in GitHub Desktop.
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