Skip to content

Instantly share code, notes, and snippets.

@kazuma1989
Created February 27, 2020 02:49
Show Gist options
  • Save kazuma1989/50cb8efec6d38b4fe340de75310a4bec to your computer and use it in GitHub Desktop.
Save kazuma1989/50cb8efec6d38b4fe340de75310a4bec to your computer and use it in GitHub Desktop.
Non-null filter
/**
* 値が 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