Function hookGuard

  • Given a Type Guard, returns a Type Guard that does exactly the same Mirrors any given guard regardless of their implementation, including negateGuard

    Example

    import { hookGuard, isNull } from 'type-guard-helpers'
    const test = {} as string | null;
    if (hookGuard(isNull, console.info, console.info)(test)) {
    test; // isNull
    }
    // hooking to log
    const before = (value: unknown, guard: unknown) => console.info(`Calling:`, { guard, value })
    const after = (result: unknown) => console.info(`Result:`, { result })
    const isNullWithLog = hookGuard(isNull, before, after)

    Type Parameters

    Parameters

    • guard: Guard
    • Optional before: ((beforeResult: {
          guard: Guard;
          value: unknown;
      }) => unknown)
        • (beforeResult: {
              guard: Guard;
              value: unknown;
          }): unknown
        • Parameters

          • beforeResult: {
                guard: Guard;
                value: unknown;
            }
            • Readonly guard: Guard
            • Readonly value: unknown

          Returns unknown

    • Optional after: ((afterResult: {
          guard: Guard;
          result: boolean;
          value: unknown;
      }) => unknown)
        • (afterResult: {
              guard: Guard;
              result: boolean;
              value: unknown;
          }): unknown
        • Parameters

          • afterResult: {
                guard: Guard;
                result: boolean;
                value: unknown;
            }
            • Readonly guard: Guard
            • Readonly result: boolean
            • Readonly value: unknown

          Returns unknown

    Returns Guard

Generated using TypeDoc