utility-pickle - v0.1.0
    Preparing search index...

    Class GuardFactory

    A static utility class for constructing parameterized type guard functions.

    GuardFactory provides factory methods that generate reusable type guards, enabling more expressive and composable runtime type checks.

    Index

    Methods

    Methods

    • Creates a type guard function that checks for strict equality against a specific reference value.

      The returned function preserves literal types (e.g., "admin" instead of string), making it useful for narrow type inference in discriminated unions or constant checks.

      Type Parameters

      • const T

      Parameters

      • value: T

        The fixed value to compare against.

      Returns GuardFunc<T>

      A type guard function that returns true if a given value is strictly equal to value.

      const isAdmin = GuardFactory.fromValue("admin");
      if (isAdmin(role)) {
      // role is now narrowed to "admin"
      }