Skip to content

Instantly share code, notes, and snippets.

@RB-Lab
Created July 17, 2020 16:45
Show Gist options
  • Save RB-Lab/2c5e872833a7088f1f6daa35f04f0291 to your computer and use it in GitHub Desktop.
Save RB-Lab/2c5e872833a7088f1f6daa35f04f0291 to your computer and use it in GitHub Desktop.
usefull small utils for TS
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