UNPKG

tiny-types

Version:

A tiny library that brings Tiny Types to JavaScript and TypeScript

22 lines (20 loc) 565 B
import { Predicate } from './Predicate'; /** * @desc Ensures that the `value` is defined as anything other than {@link null} or {@link undefined}. * * @example * import { ensure, isDefined, TinyType } from 'tiny-types'; * * class Name extends TinyType { * constructor(public readonly value: string) { * ensure('Name', value, isDefined()); * } * } * * @returns {Predicate<T>} */ export function isDefined<T>(): Predicate<T> { return Predicate.to(`be defined`, (value: T) => ! (value === null || value === undefined), ); }