```ts
/** Firmware build selection within an installed release line. */

export function compareBuilds(a: string, b: string): number {
  if (typeof a !== "string" || typeof b !== "string") {
    throw new Error("Both arguments must be strings.");
  }
  const left = a.split(".").map(Number);
  const right = b.split(".").map(Number);
  const width = Math.max(left.length, right.length);
  for (let i = 0; i < width; i += 1) {
    const x = i < left.length ? left[i] : 0;
    const y = i < right.length ? right[i] : 0;
    if (x > y) {
      return 1;
    }
    if (x < y) {
      return -1;
    }
  }
  return 0;
}

export function pickUpgrade(installed: string, offers: string[]): string | null {
  if (!Array.isArray(offers)) {
    throw new Error("Offers must be an array.");
  }

  let best: string | null = null;
  for (const offer of offers) {
    if (typeof offer !== "string" || !offer.split(".").every(Number.isInteger)) {
      continue;
    }
    const installedParts = installed.split(".");
    const offerParts = offer.split(".");
    if (installedParts[0] !== offerParts[0]) {
      continue;
    }

    const compareResult = compareBuilds(offer, installed);
    if (compareResult > 0) {
      best = offer;
    }
  }
  return best;
}
```