Support assertion functions with assertion signatures, `assertLength` and others
Opened this issue · 0 comments
tamuratak commented
Hi,
it would be useful to support assertion function with assertion signatures, assertLength
, assertMinLength
, and assertNonEmpty
. The implementation would be:
export function assertLength<T, N extends number>(
arr: readonly T[],
length: N,
): asserts arr is ReadonlyArrayExactLength<T, N> {
if (!hasLength(arr, length)) {
throw new Error(`Length is expected to be equal to ${length}, got ${arr.length}`)
}
}