@causaly/isnt
A collection of common runtime predicates that TypeScript actually understands.
![Build Status](https://github.com/causaly/isnt/actions/workflows/ci.yml/badge.svg?branch=main)
Features
- Simple API;
- Extensive tests;
- Isomorphic library, works on the browser or Node.js.
Installation
npm install @causaly/isnt
Requirements
Quick start
import { isNotNull } from '@causaly/isnt';
const array = [1, 2, null];
const arrayWithoutNull = array.filter(isNotNull);
API
Motivation
It's easy to perform a check using lodash or vanilla JavaScript, e.g.
const array = [1, 2, null].filter(Boolean);
The example above will filter out the null
value as expected (because null
is considered to be faulty).
However, TypeScript will NOT infer the correct type [playground link]. It will understand the type of array as being Array<null | number>
instead of Array<null>
.
@causaly/isnt
provides a simple API to test for predicates, while making TypeScript understand.
Contribute
Source code contributions are most welcome, as long as the linter is satisfied.
We are hiring
Causaly is building the world's largest biomedical knowledge platform, using technologies such as TypeScript, React and Node.js. Find out more about our openings at https://apply.workable.com/causaly/.
License
MIT