Adding a `partial` flag to `ReadonlyArray.groupBy` for explicit selection of partial record with ...

Could ReadonlyArray.groupBy have a partial flag or something as with other APIs, to let the user explicitly choose to get a partial record with exact property types and non empty arrays as values?

For example:
const myArray: { key: 'a' | 'b', value: number }[] = [
  { key: 'a', value: 42 },
  { key: 'a', value: 43 },
  { key: 'b', value: 44 }
]

// Record<string, number[]>
const actual = ReadonlyArray.groupBy(myArray, v => v.key)
// which is not so useful if I want to be sure to later access it with 'a' | 'b' only and expect at least one value

// Partial<Record<'a' | 'b', NonEmptyArray<number>>>
const desired = ReadonlyArray.groupBy(myArray, v => v.key, { partial: true })
// here I'm prevented from doing desired['anykey'] rightly so 
Was this page helpful?