Created
February 13, 2025 14:17
-
-
Save mrsarm/823e2fd9e015b3688abd7f89474abff8 to your computer and use it in GitHub Desktop.
isDefined: Return true only if the element is not null or undefined
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
/** | |
* Return true only if the element is not null or undefined, | |
* use it with `Array.filter` to not only filter nullable values | |
* but also to guard the type. | |
*/ | |
export const isDefined = <T>(argument: T | undefined | null): argument is T => { | |
return argument !== undefined && argument !== null; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment