```ts
/** The words grouped by their length, in first-seen order. */
export function groupByLength(words: readonly string[]): Map<number, string[]> {
  /**
   * For each word in `words`, find its corresponding bucket and add the word to it.
   *
   * If a bucket for the word's length does not exist, create a new one with the word as its first element.
   */
  const groups = new Map();
  for (const word of words) {
    const bucket = groups.get(word.length);
    if (bucket === undefined) {
      groups.set(word.length, [word]);
    } else {
      bucket.push(word);
    }
  }
  return groups;
}
```