Draft: fix(groupBy) do not return wrapped in Partial<>
#94
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
A previous MR #45 added to the return of
groupBy
that it should be wrapped inPartial<>
. This makes a lot of sense in the fact that the function could return keys that don't actually exist on the object it creates.Using the example from Ramda docs
The type that
byGrade(students)
returned previously wasRecord<'A' | 'B' | 'C' | 'D' | 'F', Student[]>
, which was accurate, but also misleading, because there was no guarantee at runtime that each of the union values existed as a key. This is why thePartial<>
as added.6 months later
HIndsight is 20/20 and we've come to learn that wrapping in
Partial<>
breaks other functionality in terms of mapping to other things.toPairs
is a prime example.The return type previously was
[<'A' | 'B' | 'C' | 'D' | 'F', Student[] | undefined][]
. The| undefined
is a problem. Because that it more inaccurate for runtime behavior that index accessing onRecord<string, Student[]>
Typescript also allows for what we were trying to solve here via the tsconfig option https://www.typescriptlang.org/tsconfig#noUncheckedIndexedAccess. Which if set gives a project a correct
Students[] | undefined
from index accessingRecord<string, Students[]>
. Which IMHO should be the default behavior forRecord<>
This MR removes the
Partial<>
wrap in the return to account for this undesired behavior.