Skip to content

fix(lib): reorder Array#reduce/reduceRight overloads in lib.d.ts#4

Open
hbrooks wants to merge 4 commits into
mainfrom
demo/pr-63064
Open

fix(lib): reorder Array#reduce/reduceRight overloads in lib.d.ts#4
hbrooks wants to merge 4 commits into
mainfrom
demo/pr-63064

Conversation

@hbrooks

@hbrooks hbrooks commented May 28, 2026

Copy link
Copy Markdown

Originally PR microsoft#63064 in microsoft/TypeScript by @taronsung

Reorder the overload declarations for reduce and reduceRight in both
ReadonlyArray<T> and Array<T> interfaces so the generic <U> overload
(with initialValue: U) is checked before the same-type overload
(with initialValue: T).

This fixes incorrect type inference when calling reduce/reduceRight
with an initial value of a different type than the array elements.

Fixes microsoft#7014
The overload order change affects the displayed type signature and
improves type inference in some cases (e.g., anyInferenceAnonymousFunctions
now correctly infers any[] instead of any when reduce is called with []
as the initial value).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants