Function assertThat

  • Type assertion that syntactically reads like prose. It uses the name of the validation function to produce the error message.

    Type Parameters

    • T

    Parameters

    • value: T
    • validate: ((value, ...args) => string | boolean)
        • (value, ...args): string | boolean
        • Parameters

          • value: T
          • Rest ...args: any[]

          Returns string | boolean

    • expectation: boolean = true
    • Rest ...args: unknown[]

    Returns T

    Example

    const isPositive = (n: number) => n >= 0

    assertThat(-5, isPositive)
    //=> throws ValidationError: Expected 'isPositive' to be 'true' for input: '-5'

    assertThat(5, isPositive, false)
    //=> throws ValidationError: Expected 'isPositive' to be 'false' for input: '5'

Generated using TypeDoc