@sapphire/utilities
Version:
Common JavaScript utilities for the Sapphire Community
21 lines (18 loc) • 837 B
text/typescript
import { Nullish } from './types.cjs';
/**
* Checks whether a value is not `null` nor `undefined`.
* This can be used in {@link Array.filter} to remove `null` and `undefined` from the array type
* @param value The value to verify that is neither `null` nor `undefined`
* @returns A boolean that is `true` if the value is neither `null` nor `undefined`, false otherwise.
* @example
* ```typescript
* // TypeScript Type: (string | undefined | null)[]
* const someArray = ['one', 'two', undefined, null, 'five'];
*
* // TypeScript Type: string[]
* const filteredArray = someArray.filter(filterNullAndUndefined);
* // Result: ['one', 'two', 'five']
* ```
*/
declare function filterNullAndUndefined<TValue>(value: TValue | Nullish): value is TValue;
export { filterNullAndUndefined, filterNullAndUndefined as filterNullish };