Created
August 30, 2022 06:09
-
-
Save luigircruz/d9103f20002d7dba72dc8fd3f4e06a3a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * Type guard to filter out null-ish values | |
| * | |
| * @category Guards | |
| * @example array.filter(notNullish) | |
| */ | |
| export function notNullish<T>(v: T | null | undefined): v is NonNullable<T> { | |
| return v != null | |
| } | |
| /** | |
| * Type guard to filter out null values | |
| * | |
| * @category Guards | |
| * @example array.filter(noNull) | |
| */ | |
| export function noNull<T>(v: T | null): v is Exclude<T, null> { | |
| return v !== null | |
| } | |
| /** | |
| * Type guard to filter out null-ish values | |
| * | |
| * @category Guards | |
| * @example array.filter(notUndefined) | |
| */ | |
| export function notUndefined<T>(v: T): v is Exclude<T, undefined> { | |
| return v !== undefined | |
| } | |
| /** | |
| * Type guard to filter out falsy values | |
| * | |
| * @category Guards | |
| * @example array.filter(isTruthy) | |
| */ | |
| export function isTruthy<T>(v: T): v is NonNullable<T> { | |
| return Boolean(v) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment