```ts
export function shelfFit(widths: number[], shelf: number): number {
  if (!Array.isArray(widths) || !widths.every(w => typeof w === 'number' && w > 0)) {
    throw new Error('Invalid widths argument');
  }
  if (typeof shelf !== 'number' || shelf < 0) {
    throw new Error('Invalid shelf width argument');
  }

  let booksOnShelf = 0;
  for (const width of widths) {
    if (width > shelf) break;
    booksOnShelf++;
  }

  return booksOnShelf;
}
```