```ts
/**
 * A fixed-capacity least-recently-used cache.
 */
export class LruCache<K, V> {
  private readonly capacity: number;
  private readonly map: Map<K, V>;

  /**
   * Creates a new LruCache with the given positive integer capacity.
   * @throws Error if capacity is not a positive integer
   */
  constructor(capacity: number) {
    if (!Number.isInteger(capacity) || capacity <= 0) {
      throw new Error('capacity must be a positive integer');
    }
    this.capacity = capacity;
    this.map = new Map<K, V>();
  }

  /**
   * Retrieves the value associated with key, or undefined if not present.
   * Marks the entry as recently used if found.
   */
  get(key: K): V | undefined {
    if (!this.map.has(key)) return undefined;
    const value = this.map.get(key)!; // non-undefined due to has check
    this.map.delete(key);
    this.map.set(key, value); // move to most recent
    return value;
  }

  /**
   * Inserts or updates the key with the given value.
   * Marks the entry as recently used. Evicts least-recently-used if capacity exceeded.
   */
  set(key: K, value: V): void {
    if (this.map.has(key)) this.map.delete(key);
    this.map.set(key, value);
    if (this.map.size > this.capacity) {
      const lruKey = this.map.keys().next().value;
      if (lruKey !== undefined) this.map.delete(lruKey);
    }
  }

  /**
   * Current number of entries in the cache.
   */
  get size(): number {
    return this.map.size;
  }
}
```