UNPKG

option-t

Version:

A toolkit of Nullable/Option/Result type implementation in ECMAScript. Their APIs are inspired by Rust's `Option<T>` and `Result<T, E>`.

21 lines (20 loc) 994 B
import type { FilterFn, TypePredicateFn } from '../../internal/function.js'; import { type Nullable, type NotNull } from '../core/nullable.js'; /** * Returns `null` if the _input_ is `null`, * otherwise calls _predicate_ with the _input_ `T` and returns: * * * `T` if _predicate_ returns `true`. * * `null` if _predicate_ returns `false`. */ export declare function filterForNullable<T>(input: Nullable<T>, predicate: FilterFn<T>): Nullable<T>; /** * Returns `null` if the _input_ is `null`, * otherwise calls _predicate_ with the _input_ `T` and returns: * * * The input value as `U` if _predicate_ returns `true` which means that _predicate_ says the input value is U. * * `null` if _predicate_ returns `false`. * * Please use {@link filterForNullable} generally if you don't have to narrow the type. */ export declare function filterWithEnsureTypeForNullable<T, U extends T>(input: Nullable<T>, predicate: TypePredicateFn<T, NotNull<U>>): Nullable<U>;