optional.ts
1 export type Optional<T> = T | None; 2 export type None = null | undefined; 3 4 /** 5 * Determine if an optional value is present. 6 * 7 * @param optional value 8 * @return true if present, false otherwise 9 */ 10 export function isSome<T>(optional: Optional<T>): optional is T { 11 return optional !== null && optional !== undefined; 12 } 13 14 /** 15 * Determine if an optional value is not present. 16 * 17 * @param optional value 18 * @return true if not present, false otherwise 19 */ 20 export function isNone<T>(optional: Optional<T>): optional is None { 21 return optional === null || optional === undefined; 22 }