first-defined
v1.0.0
Published
Return the first defined item in an array
Downloads
3
Maintainers
Readme
Return the first defined item in an array.
Installation
yarn add first-defined
npm install first-defined
Usage
import { firstDefined } from "first-defined";
firstDefined([undefined, 1]); // 1
firstDefined([undefiend, undefined], 2); // 2
firstDefined([undefined, undefined]); // undefined
Types
type Defined<T extends any = any> = Exclude<T, undefined>;
type Maybe<T extends any> = T | undefined;
function firstDefined<T extends Defined>(list: Maybe<T>[], defaultValue?: T): Maybe<T>;
- @bconnorwhite/bob: Bob is a toolkit for TypeScript projects