Created
February 19, 2021 14:23
-
-
Save leolabs/4c6431989db8470c05fd9f8cb3c44d93 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 Falsy = false | 0 | '' | null | undefined; | |
type NonFalsy<T> = T extends Falsy ? never : T; | |
/** | |
* Filter out falsy entries in an array | |
*/ | |
export function isTruthy<T>(value: T): value is NonFalsy<T> { | |
return Boolean(value); | |
} | |
const array: Array<string | null> = [/* ... */]; | |
array.filter(isTruthy) // Array<string> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment