```typescript
/**
 * The index of target in a sorted array, or -1. Handles duplicates by finding the first occurrence.
 */
export function binarySearch(items: readonly number[], target: number): number {
  let low = 0;
  let high = items.length;
  
  while (low < high) {
    const mid = Math.floor(low + (high - low) / 2);

    if (items[mid] === target) {
      // Ensure the target is found in the first occurrence of duplicates
      high = mid;
    } else if (items[mid] < target) {
      low = mid + 1;
    } else {
      // Handle duplicates by finding first occurrence
      high = mid;
    }
  }

  return items[low] === target ? low : -1;
}
```