Skip to content
Snippets Groups Projects
Unverified Commit ebf064e7 authored by Chuck Grindel's avatar Chuck Grindel Committed by GitHub
Browse files

chore(utils/array): add isNotNullOrUndefined (#22081)

parent b5d87c67
No related branches found
No related tags found
No related merge requests found
import { isNotNullOrUndefined } from './array';
describe('util/array', () => {
it.each`
a | exp
${null} | ${false}
${undefined} | ${false}
${{ name: 'foo' }} | ${true}
`('.isNotNullOrUndefined', ({ a, exp }) => {
expect(isNotNullOrUndefined(a)).toEqual(exp);
});
});
......@@ -10,3 +10,12 @@ export function coerceArray<T>(input: T[] | null | undefined): T[] {
export function sortNumeric(a: number, b: number): number {
return a - b;
}
// Useful for filtering an array so that it includes values that are not null or
// undefined. This predicate acts as a type guard so that the resulting type for
// `values.filter(isNotNullOrUndefined)` is `T[]`.
export function isNotNullOrUndefined<T>(
value: T | undefined | null
): value is T {
return !is.nullOrUndefined(value);
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment