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

groupBy partial object creates issues with downstream usage. #113

Closed
AndrewSouthpaw opened this issue Mar 23, 2024 · 2 comments
Closed

groupBy partial object creates issues with downstream usage. #113

AndrewSouthpaw opened this issue Mar 23, 2024 · 2 comments

Comments

@AndrewSouthpaw
Copy link

Here's a sample usage of groupBy:

it("test", () => {
  type Foo = { id: number; color: string };
  const byColor = groupBy(({ color }) => color, [
    { color: "red", id: 1 },
    { color: "blue", id: 2 },
    { color: "red", id: 3 },
  ] as Foo[]);
  Object.values(byColor).map((grouping: Foo[]) => {
    console.log(grouping);
  });
});

which triggers this error:

image

The map parameter needs to be supplied with Foo[] | undefined to work correctly, even though that's not the right type.

Removing the Partial wrapping the return type would fix this DX issue... I'm wondering what is the rationale for providing a partial record type?

@Harris-Miller
Copy link
Collaborator

The suggestion to add the Partial<> was made and merged in this MR: #45

Your issue has already been brought up and resolved. Please see here: #91

@AndrewSouthpaw
Copy link
Author

Oh, sorry I didn't search for groupBy in the issues before posting! My bad, and thanks for the response. I'll move any subsequent questions there.

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