Skip to content

Conversation

@jaycle
Copy link
Collaborator

@jaycle jaycle commented Jul 4, 2018

No description provided.

@jaycle jaycle requested a review from mardotio July 4, 2018 20:11
return arr.reduce<ObjOfObjs<T>>(
(ordered, el) => {
if (el[key] in ordered) {
ordered[el[key]].push(el);
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Spread didn't work. Maybe with microsoft/TypeScript#13288 but not sure. I tested this and it works well though.

return ordered;
},
{}
{} as {[key in string]: T[]}
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just moved the type here instead. Do you think explicitly naming it was better?

Copy link
Owner

@mardotio mardotio left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good

{}
);
};
export const array2HashByKey = <T extends Record<K, string>, K extends keyof T>(arr: T[], key: K) => (
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does there need to be a blank line here?

@jaycle jaycle merged commit 9dfa59f into master Jul 7, 2018
@jaycle jaycle deleted the type_sorting branch November 3, 2018 18:18
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

Successfully merging this pull request may close these issues.

3 participants