<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/filter-nullish-values-in-typescript-wfbba55ct" -->

---
title: Filter nullish values in TypeScript | daily.dev
description: Using filter(Boolean) to remove null and undefined values from an array also strips out 0, false, and empty strings, which can silently remove valid data. A...
canonical: https://daily.dev/posts/filter-nullish-values-in-typescript-wfbba55ct
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: Filter nullish values in TypeScript | daily.dev
og:description: Using filter(Boolean) to remove null and undefined values from an array also strips out 0, false, and empty strings, which can silently remove valid data. A...
og:url: https://daily.dev/posts/filter-nullish-values-in-typescript-wfbba55ct
og:image: https://api.daily.dev/og/posts/wfBbA55CT.png
og:image:alt: Filter nullish values in TypeScript
og:image:width: 1200
og:image:height: 630
og:locale: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Filter nullish values in TypeScript

**[Open Source](https://daily.dev/sources/opensourcesquad)** · [@nyaomaru](https://daily.dev/nyaomaru) · 1 min read · 15 upvotes · 6 comments

## Summary

Using filter(Boolean) to remove null and undefined values from an array also strips out 0, false, and empty strings, which can silently remove valid data. A recommended alternative is filter(isNotNil), a type guard that narrows the array type correctly while only excluding null and undefined.

## Content

`filter(Boolean)` removes more than null and undefined, it also drops 0, false, and "".

Use `filter(isNotNil)` when those are valid values, and keep the narrowed result type.

[https://is-kit.dev/guides/filter-null-and-undefined](https://is-kit.dev/guides/filter-null-and-undefined)

#typescript #opensource #cleancode

## Community discussion

Top comments from developers on daily.dev.

**@webry** · 3 upvotes

> `filter(e => e != null)` , one less future Shai-Hulud.
>
> PS: Looking at the actual library, I like general declarative practice and TS type predicates, however for most projects this can be done without a library.

**@agustinbarrientos** · 2 upvotes

> Could a type-aware ESLint rule flag `filter(Boolean)` when the union includes `0`, `false`, or an empty string? I'd avoid autofixing because the intended predicate isn't always nullish.

**@guytsitsiashvili** · 1 upvotes

> I read the source-code, it contains so much internal overhead for the sake of completeness.
>
> I understand the and also suffer from the urge to be loyal to the archirtecture.
>
> but seeing this level of runtime cost is concerning.
>
> ![image.png](https://media.daily.dev/image/upload/s--SDzaHry_--/f_auto/v1788431117/ugc/content_005622b5-3fd6-4f16-883f-a87b92a36839?_a=BAMAMicg0)
>
> Instead you could've gone with:
>
> ```ts
> export const isNotNil = <T>(value: T): value is NonNullable<T> => value != null
> ```

## Similar posts on daily.dev

- [Stop Using TypeScript's Exclamation Mark](https://daily.dev/posts/stop-using-typescript-s-exclamation-mark-re1atfub4) · TypeScript.TV · 258 upvotes · 16 comments
- [Handling Null and Undefined with ‘??’](https://daily.dev/posts/handling-null-and-undefined-with--vopbeffru) · JavaScript in Plain English · 26 upvotes · 1 comments
- [TypeScript Discriminated Unions: Safe Narrowing and Checks](https://daily.dev/posts/typescript-discriminated-unions-safe-narrowing-and-checks-bywqozkte) · SitePoint · 23 upvotes · 0 comments
- [Omit for Discriminated Unions in TypeScript](https://daily.dev/posts/omit-for-discriminated-unions-in-typescript-ujl0mde1h) · TkDodo · 7 upvotes · 0 comments

---

Tags: [#typescript](https://daily.dev/tags/typescript)

[View this post on daily.dev](https://daily.dev/posts/filter-nullish-values-in-typescript-wfbba55ct)

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://daily.dev/#organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180},"sameAs":["https://twitter.com/dailydotdev","https://github.com/dailydotdev","https://www.linkedin.com/company/daily-dev-ltd"]},{"@type":"WebSite","@id":"https://daily.dev/#website","url":"https://daily.dev","name":"daily.dev","publisher":{"@id":"https://daily.dev/#organization"},"potentialAction":{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https://daily.dev/search?q={search_term_string}"},"query-input":"required name=search_term_string"}}]}
{"@context":"https://schema.org","@type":"DiscussionForumPosting","mainEntityOfPage":"https://daily.dev/posts/filter-nullish-values-in-typescript-wfbba55ct","headline":"Filter nullish values in TypeScript","text":"Using filter(Boolean) to remove null and undefined values from an array also strips out 0, false, and empty strings, which can silently remove valid data. A recommended alternative is filter(isNotNil), a type guard that narrows the array type correctly while only excluding null and undefined.","url":"https://daily.dev/posts/filter-nullish-values-in-typescript-wfbba55ct","datePublished":"2026-08-28T14:27:05.180Z","dateModified":"2026-09-13T21:33:27.766Z","author":{"@type":"Person","name":"nyaomaru","url":"https://daily.dev/nyaomaru","image":"https://avatars.githubusercontent.com/u/90489696?v=4","interactionStatistic":{"@type":"InteractionCounter","interactionType":{"@type":"EndorseAction"},"userInteractionCount":400}},"image":"https://media.daily.dev/image/upload/s--Q-q4PlIw--/f_auto/v1787927189/posts/WhlKufRDx?_a=BAMAMicg0","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":15},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":6}],"comment":[{"@type":"Comment","text":"filter(e =\u0026gt; e != null) , one less future Shai-Hulud.\nPS: Looking at the actual library, I like general declarative practice and TS type predicates, however for most projects this can be done without a library.","datePublished":"2026-08-28T17:27:16.557Z","dateModified":"2026-08-28T17:46:57.455Z","url":"https://daily.dev/posts/wfBbA55CT#c-OU30gvo2i","author":{"@type":"Person","name":"Samuel Braun","url":"https://daily.dev/webry","image":"https://media.daily.dev/image/upload/v1683105442/avatars/avatar_KjrWzAyEMnN7TAr8iPV9O.jpg"},"interactionStatistic":{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":3}},{"@type":"Comment","text":"Could a type-aware ESLint rule flag filter(Boolean) when the union includes 0, false, or an empty string? I’d avoid autofixing because the intended predicate isn’t always nullish.","datePublished":"2026-08-30T17:05:23.656Z","url":"https://daily.dev/posts/wfBbA55CT#c-ET4ErJm3W","author":{"@type":"Person","name":"Agustin Barrientos","url":"https://daily.dev/agustinbarrientos","image":"https://media.daily.dev/image/upload/s--5ayxQnqn--/f_auto/v1788281802/avatars/avatar_wQYYVe5Tbj0NJ7C7qPoa8?_a=BAMAMicg0"},"interactionStatistic":{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":2}},{"@type":"Comment","text":"I read the source-code, it contains so much internal overhead for the sake of completeness.\nI understand the and also suffer from the urge to be loyal to the archirtecture.\nbut seeing this level of runtime cost is concerning.\n\nInstead you could’ve gone with:\nexport const isNotNil = \u0026lt;T\u0026gt;(value: T): value is NonNullable\u0026lt;T\u0026gt; =\u0026gt; value != null","datePublished":"2026-09-03T10:26:36.589Z","url":"https://daily.dev/posts/wfBbA55CT#c-PDo5BVqzy","author":{"@type":"Person","name":"Guy Tsitsiashvili","url":"https://daily.dev/guytsitsiashvili","image":"https://lh3.googleusercontent.com/a/ACg8ocK1LyZjC8SM71W8hhWUJzUSq90mNWKLW-XOURtOFT8QezMHXQ=s96-c"},"interactionStatistic":{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":1}}],"isPartOf":{"@type":"WebPage","url":"https://daily.dev/squads/opensourcesquad","name":"Open Source"}}
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://daily.dev"},{"@type":"ListItem","position":2,"name":"Open Source","item":"https://daily.dev/squads/opensourcesquad"},{"@type":"ListItem","position":3,"name":"Filter nullish values in TypeScript"}]}
```

