Created
February 27, 2020 02:49
-
-
Save kazuma1989/50cb8efec6d38b4fe340de75310a4bec to your computer and use it in GitHub Desktop.
Non-null filter
This file contains 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
/** | |
* 値が null または undefined のときは false, それ以外の値のときは true を返す。 | |
* Array.prototype.filter と組み合わせて null を除去するのに使える。 | |
* | |
* @param value null チェックしたい値 | |
* @example | |
* [0, null, {}].filter(nonNull) // [0, {}] | |
*/ | |
export function nonNull<T>(value: T | null | undefined): value is T { | |
return value !== null && value !== undefined | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment