Created
July 17, 2020 16:45
-
-
Save RB-Lab/2c5e872833a7088f1f6daa35f04f0291 to your computer and use it in GitHub Desktop.
usefull small utils for TS
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
export function notEmpty<TValue>( | |
value: TValue | null | undefined | |
): value is TValue { | |
return value !== null && value !== undefined; | |
} | |
export type Maybe<T> = null | undefined | T; | |
export function filterMaybeArrayMaybe<T>(array: Maybe<Maybe<T>[]>) { | |
if (array === null || array === undefined) { | |
return []; | |
} | |
return array.filter(notEmpty); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment