Alias for checkNotUndefined
Shorthand notation for converting an unexpected null/undefined reference to a more telling error message.
E.g
const mapElement = checkNotNull(document.getElementById('map'), 'Missing #map element in DOM');
will result in a strongly-typed HTMLElement
which cannot be null, or throw an Error with a dedicated message
(rather than simply crashing with a null-pointer reference when used later).
An object of a union type including null and undefined.
An optional message to throw as Error message.
A non-null object
Alias for isNotUndefined
A type guard which uses generics to narrow a "type
or null
or undefined
" to "type
".
This is particularly useful with RxJs filter, as it recognizes the narrowing and infers the type of the resulting stream.
Alias for undefinedSafe
Converts the given function to a new function which calls through to the original function except if the input is
undefined
, in which case the function returns undefined. In other words, it wraps a function to guard it against
undefined
input.
Returns a trimmed string, or undefined
if the string ends up empty.
Returns a trimmed string, converting undefined
to an empty string.
Converts the given function to a new function which calls through to the original function except if the input is
undefined
, in which case the function returns undefined. In other words, it wraps a function to guard it against
undefined
input.
Converts the given function to a new function which calls through to the original function except if the input is
undefined
, in which case the function returns undefined. In other words, it wraps a function to guard it against
undefined
input.
This module contains functions to fail-fast on null/undefined, and do various type guards and narrowing in TypeScript.