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

---
title: Filter nullish values in TypeScript | daily.dev
description: Using filter(Boolean) to remove null and undefined values also strips out other falsy values like 0, false, and empty strings, which can cause bugs when those...
canonical: https://daily.dev/posts/filter-nullish-values-in-typescript-qaycm73rm
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 also strips out other falsy values like 0, false, and empty strings, which can cause bugs when those...
og:url: https://daily.dev/posts/filter-nullish-values-in-typescript-qaycm73rm
og:image: https://api.daily.dev/og/posts/QAyCM73rm.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

**[nyaomaru](https://daily.dev/sources/graxwfjk0eop4zs3tdzdr)** · [@nyaomaru](https://daily.dev/nyaomaru) · 1 min read · 0 upvotes · 0 comments

## Summary

Using filter(Boolean) to remove null and undefined values also strips out other falsy values like 0, false, and empty strings, which can cause bugs when those are legitimate values. A dedicated isNotNil predicate filters only null and undefined while preserving TypeScript's narrowed result type.

## 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

## 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

---

Tags: [#javascript](https://daily.dev/tags/javascript), [#typescript](https://daily.dev/tags/typescript), [#functional-programming](https://daily.dev/tags/functional-programming)

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

```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-qaycm73rm","headline":"Filter nullish values in TypeScript","text":"Using filter(Boolean) to remove null and undefined values also strips out other falsy values like 0, false, and empty strings, which can cause bugs when those are legitimate values. A dedicated isNotNil predicate filters only null and undefined while preserving TypeScript's narrowed result type.","url":"https://daily.dev/posts/filter-nullish-values-in-typescript-qaycm73rm","datePublished":"2026-08-28T14:26:26.941Z","dateModified":"2026-08-28T14:26:47.197Z","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":390}},"image":"https://media.daily.dev/image/upload/s--4m-tkP32--/f_auto/v1787927188/posts/QAyCM73rm?_a=BAMAMicg0","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":0},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":0}],"isPartOf":{"@type":"WebPage","url":"https://daily.dev/sources/graxwfjk0eop4zs3tdzdr","name":"nyaomaru"}}
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://daily.dev"},{"@type":"ListItem","position":2,"name":"nyaomaru","item":"https://daily.dev/sources/graxwfjk0eop4zs3tdzdr"},{"@type":"ListItem","position":3,"name":"Filter nullish values in TypeScript"}]}
```

