A type-validation that checks if a value is an empty array.
Value to validate
Type: unknown
Optional callback that would be called with validation rejection reasons.
- When validation succeeds -
rejectionReasonswould not be invoked. - When validation fails -
rejectionReasonswould be invoked at least once and may be invoked multiple times.
A description of the validated type
Type: string
Returns a predicate (no second argument) for the specified validator.
Returns a type-guard predicate (no second argument) for the specified validator.
import { isEmptyArray, typeValidatorType } from '@altostra/type-validations'
console.log(isEmptyArray[typeValidatorType]) // []
console.log(isEmptyArray([], console.log)) // true
console.log(isEmptyArray('A', console.log)) /* { path: [], reason: "Value <'A'> is not an array", propertyType: '[]' }
false */
console.log(isEmptyArray([0], console.log)) /* { path: [], reason: 'Array <[ 0 ]> is not empty', propertyType: '[]' }
false */
const incognito: unknown = []
if (isEmptyArray(incognito)) {
console.log(incognito.length) // 0
// @ts-expect-error: This condition will always return 'false' since
// the types '0' and '1' have no overlap.
console.log(incognito.length === 1) // false
}