isguard-ts
    Preparing search index...

    Function isPartialRecord

    • Creates a PartialRecordTypeGuard that checks that the value is a partial record with the specified keys and value type.

      Type Parameters

      • const K extends readonly PropertyKey[]

        Array of keys for the record

      • V

        The value type for all keys

      Parameters

      • keys: K

        The keys that may be present in the record

      • isValue: TypeGuard<V>

        The type guard for the values

      Returns PartialRecordTypeGuard<K, V>

      A type guard for Partial<Record<K, V>>

      const timeUnits = ["second", "minute", "hour"] as const;
      const isPartialTimeRecord = isPartialRecord(timeUnits, isNumber);
      // ^? TypeGuard<Partial<Record<"second" | "minute" | "hour", number>>>

      isPartialTimeRecord({ second: 1 }); // true
      isPartialTimeRecord({}); // true
      isPartialTimeRecord({ second: "1" }); // false (wrong value type)