A simple `unwrap` function for use with TypeScript.
npm install ts-unwrapA simple unwrap function for use with TypeScript.
``sh`
npm install --save ts-unwrap
`js
import unwrap from 'ts-unwrap'
// port is of type string, and will never be undefined
const port = unwrap(process.env['PORT'])
// optionally specify a custom error message
const port = unwrap(process.env['PORT'], 'Missing PORT from environment')
`
Throws an error if the value is undefined or null, otherwise it returns the value.
The description of the thrown error will be 'Missing value' unless another message is passed as the errorMessage argument.
- ts-todo
- ts-unimplemented
- ts-unreachable
- Rust unwrap` method