isguard-ts
    Preparing search index...

    Function isOptional

    • Creates an OptionalTypeGuard that checks that the value is either undefined or of type T.

      Can be shortened with TypeGuard.optional.

      Type Parameters

      • T

        The type to make optional

      Parameters

      • guard: TypeGuard<T>

        The type guard for the base type T

      Returns OptionalTypeGuard<T>

      A type guard for T | undefined

      const isOptionalNumber = isOptional(isNumber); // or isNumber.optional()

      isOptionalNumber(5); // true
      isOptionalNumber(undefined); // true
      isOptionalNumber("hello"); // false