Skip to content

Object.groupBy types are wrong (remove Partial<>) #1943

Closed as not planned
Closed as not planned
@fregante

Description

@fregante

This isn't possible. Each key of grouped and its value must exist:

const grouped = Object.groupBy(
  [
      {
          name: "foo",
          value: 20,
      },
      {
          name: "bar",
          value: 60,
      },
      {
          name: "bar",
          value: 40,
      }
  ],
  ({name}) => name,
);
for (const group of Object.values(grouped)) {
  group.forEach(console.log)
  // 'group' is possibly 'undefined'.(18048)
}

https://www.typescriptlang.org/play/?checkJs=true&allowJs=true&target=99&types=%5B%22node%22%5D#code/FAAhGMHsDsGcBcQHMBOkCuAHApgExALwgDyARgFbbjwB0qGmAQgJ4AUoYIA2h55wN68+w6AEMAttgBcIAEQAzSJFkAaIcM4A3UQBt00kACYADGo1gAvmfODzIiQdmlRKVevPa9BgGyn3l6w1bO04xSRknFzcQrV19GQAWPzsLIQBdQJBWfjDsCwBKQgA+EFzrfIBuDkUULKg4RHosEEh5EgoqWk99WFYmnFx8wuCwfpoagFFRcAALVnrYSB1sGh1IJHyhAHotkAByfr2QAEtYEExIWFhj0h1mffRoXGx5Y+g8PZpWAEYADmMEr9NpYgA

Additional comments may be found on microsoft/TypeScript#47171 (comment)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions