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

Add types to array2HashByKey #37

Merged
merged 4 commits into from
Jul 7, 2018
Merged

Add types to array2HashByKey #37

merged 4 commits into from
Jul 7, 2018

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.

@@ -16,6 +12,6 @@ export const array2HashByKey = <T extends HasString<K>, K extends keyof T & stri
}
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.

2 participants