Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(reduce): proper TypeScript signature overload ordering (#2382)
* fix(reduce): adjust overload ordering Fixes #2338 * Make seed required when not of type T * Added specs for new and old behavior of reduce overloads and fixed failing specs This adds tests for both existing behavior, under the old overload, and the new behavior enabled by the new overload signatures of the `reduce` operator. Not that the specific change to the following test case `'should accept T typed reducers'` that removes the seed value. If a seed value is specified, then the reduction is always from `T` to `R`. This was necessary to make the test pass, but also models the expected behavior more correctly. The cases for `R` where `R` is not assignable to `T` are covered by new tests added in the commit. Additionally, I have added additional verification to all of the tests touched by this change to ensure that the values returned are usable as their respective expected types. * Fix ordering as allowed by newly required seeds to fix failing specs Fix ordering as allowed by newly required seeds to fix failing tests. I think there is a good argument to be made that the failing tests were failing correctly, as this is how `Array.prototype.reduce` behaves, but as I have made the seed arguments required, for `R` typed reducers, re-ordering the overloads impacts their specificity allowing, the current behavior, correct or otherwise, to be retained.
- Loading branch information