Skip to content

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

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

Closed
fregante opened this issue Mar 21, 2025 · 1 comment
Closed

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

fregante opened this issue Mar 21, 2025 · 1 comment

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)

@saschanaz
Copy link
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.

@fregante fregante closed this as not planned Won't fix, can't repro, duplicate, stale Mar 30, 2025
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

2 participants