isguard-ts
    Preparing search index...

    Function isRecord

    • Creates a RecordTypeGuard that checks that the value has the specified keys with the specified 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 must be present in the record

      • isValue: TypeGuard<V>

        The type guard for the values

      Returns RecordTypeGuard<K, V>

      A type guard for Record<K, V>

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

      isTimeRecord({ second: 1, minute: 2, hour: 3 }); // true
      isTimeRecord({ second: 1 }); // false