```typescript
/**
 * The words grouped by their length, in first-seen order.
 */
export function groupByLength(words: readonly string[]): Map<number, string[]> {
  const groups = new Map();
  for (const word of words) {
    if (!Number.isInteger(word.length)) {
      throw new Error(`Invalid argument: word length must be an integer, but got ${word.length}`);
    }
    const bucket = groups.get(word.length);
    if (bucket === undefined) {
      groups.set(word.length, [word]);
    } else {
      bucket.push(word);
    }
  }
  return groups;
}
```