is-truthy-ts
TypeScript icon, indicating that this package has built-in type declarations

1.0.2 • Public • Published

is-truthy-ts

A type predicate for truthy values

Install

npm install is-truthy-ts

The problem

Often you want to filter out nullish values from an array, but typescript doesn't type the result correctly by default:

const arrayWithNulls = [1, 2, null, 4];

const filtered = arrayWithNulls.filter(Boolean);
// ❌ The type of filtered is (number | null)[]

Solution

import { isTruthy } from 'is-truthy-ts';

const arrayWithNulls = [1, 2, null, 4];
const filtered = arrayWithNulls.filter(Boolean);
// ✅ The type of filtered is number[]

Package Sidebar

Install

npm i is-truthy-ts

Weekly Downloads

59

Version

1.0.2

License

MIT

Unpacked Size

4.72 kB

Total Files

14

Last publish

Collaborators

  • everdimension