Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
fregante opened this issue Mar 21, 2025 · 0 comments
Open

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

fregante opened this issue Mar 21, 2025 · 0 comments

Comments

@fregante
Copy link

fregante commented Mar 21, 2025

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant