Skip to content

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

Closed as not planned
Closed as not planned

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)

Activity

  1. saschanaz commented on Mar 30, 2025

    @saschanaz
    Contributor

    Object is part of JS API rather than Web Platform API. This should be solved in TypeScript repo, not here. Please file a new issue there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to 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