function isNonNull<T>(val: T | null | undefined): val is T {

	return val !== null && val !== undefined;

}

const cleanupNullsinArray = cleanupNulls.filter(isNonNull);

https://www.reddit.com/r/typescript/comments/hkndzx/comment/fwtttlg/?utm_source=share&utm_medium=web2x&context=3