Library API
    Preparing search index...

    Function when

    • Conditionally coalesces a value based on a predicate guard. Returns the value (narrowed by the guard) if the guard returns true, otherwise returns the fallback.

      Type Parameters

      • T

      Parameters

      • value: unknown

        The candidate value to test

      • guard: (v: unknown) => v is T

        A predicate or type guard function

      Returns T | undefined

      The value or fallback

      when('hello', isString);              // 'hello'
      when(123, isString); // undefined
      when(123, isString, 'default'); // 'default'
      when(rawIso, v => v !== 'INVALID'); // rawIso or undefined
    • Conditionally coalesces a value based on a predicate guard. Returns the value (narrowed by the guard) if the guard returns true, otherwise returns the fallback.

      Type Parameters

      • T

      Parameters

      • value: unknown

        The candidate value to test

      • guard: (v: unknown) => v is T

        A predicate or type guard function

      • fallback: undefined

        Optional fallback value if the guard returns false

      Returns T | undefined

      The value or fallback

      when('hello', isString);              // 'hello'
      when(123, isString); // undefined
      when(123, isString, 'default'); // 'default'
      when(rawIso, v => v !== 'INVALID'); // rawIso or undefined
    • Conditionally coalesces a value based on a predicate guard. Returns the value (narrowed by the guard) if the guard returns true, otherwise returns the fallback.

      Type Parameters

      • T
      • U

      Parameters

      • value: unknown

        The candidate value to test

      • guard: (v: unknown) => v is T

        A predicate or type guard function

      • fallback: U

        Optional fallback value if the guard returns false

      Returns T | U

      The value or fallback

      when('hello', isString);              // 'hello'
      when(123, isString); // undefined
      when(123, isString, 'default'); // 'default'
      when(rawIso, v => v !== 'INVALID'); // rawIso or undefined
    • Conditionally coalesces a value based on a predicate guard. Returns the value (narrowed by the guard) if the guard returns true, otherwise returns the fallback.

      Type Parameters

      • T

      Parameters

      • value: T

        The candidate value to test

      • guard: (v: T) => boolean

        A predicate or type guard function

      Returns T | undefined

      The value or fallback

      when('hello', isString);              // 'hello'
      when(123, isString); // undefined
      when(123, isString, 'default'); // 'default'
      when(rawIso, v => v !== 'INVALID'); // rawIso or undefined
    • Conditionally coalesces a value based on a predicate guard. Returns the value (narrowed by the guard) if the guard returns true, otherwise returns the fallback.

      Type Parameters

      • T
      • U

      Parameters

      • value: T

        The candidate value to test

      • guard: (v: T) => boolean

        A predicate or type guard function

      • fallback: U

        Optional fallback value if the guard returns false

      Returns T | U

      The value or fallback

      when('hello', isString);              // 'hello'
      when(123, isString); // undefined
      when(123, isString, 'default'); // 'default'
      when(rawIso, v => v !== 'INVALID'); // rawIso or undefined