```typescript
/** The words grouped by their length, in first-seen order. */
export function groupByLength(words: readonly string[]): Map<number, string[]> {
  const groups = new Map<string[], number[]>();
  for (const word of words) {
    let bucket = groups.get(word.length);
    if (bucket === undefined) {
      bucket = [];
    }
    groups.set(word.length, bucket);
    bucket.push(word);
  }
  return groups;
}
```