Skip to content

Support assertion functions with assertion signatures, assertLength and others #2

Open
@tamuratak

Description

@tamuratak

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}`)
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions