-
Notifications
You must be signed in to change notification settings - Fork 0
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
Conversation
return arr.reduce<ObjOfObjs<T>>( | ||
(ordered, el) => { | ||
if (el[key] in ordered) { | ||
ordered[el[key]].push(el); |
There was a problem hiding this comment.
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[]} |
There was a problem hiding this comment.
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?
There was a problem hiding this 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) => ( |
There was a problem hiding this comment.
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?
No description provided.