Skip to main content

isDefined

function isDefined<T>(t?): T & 
| null
| {
};

Test that a value t is set to something and return it, throws on undefined.

This is handy when selecting using an index to eliminiate the infered undefined type.

Type Parameters

Type Parameter
T

Parameters

ParameterType
t?T

Returns

T & | null | { }

Example

console.log(isDefined('')); // =\> ''
console.log(isDefined(0)); // =\> 0
console.log(isDefined(false)); // =\> false
console.log(isDefined(null)); // =\> null
console.log(isDefined(undefined)); // will throw