@quentinadam/require
v0.1.4
Published
A simple function that returns and requires that a value is not undefined or null
Downloads
282
Readme
@quentinadam/require
A simple function that returns and requires that a value is not undefined or null.
Usage
import require from '@quentinadam/require';
const a = require(1); // doesn't throw
const b = require(undefined); // throws an AssertionError
require(undefined, 'message'); // throws an AssertionError with a custom error message
require(undefined, new Error('message')); // throws a custom Error
const value: string | undefined = 'hello';
const narrowedValue = require(value); // narrows the type of value to string;
value.toUpperCase(); // works