Skip to content

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

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Open
tamuratak opened this issue Apr 8, 2023 · 0 comments
Labels
enhancement New feature or request

Comments

@tamuratak
Copy link

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}`)
    }
}
@uhyo uhyo added the enhancement New feature or request label Apr 9, 2023
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants