Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

fix(lib): reorder Array#reduce/reduceRight overloads so generic <U> variant is tried first#10

Open
hbrooks wants to merge 1 commit into
mainellipsis-dev-test/TypeScript:mainfrom
demo/pr-63440ellipsis-dev-test/TypeScript:demo/pr-63440Copy head branch name to clipboard
Open

fix(lib): reorder Array#reduce/reduceRight overloads so generic <U> variant is tried first#10
hbrooks wants to merge 1 commit into
mainellipsis-dev-test/TypeScript:mainfrom
demo/pr-63440ellipsis-dev-test/TypeScript:demo/pr-63440Copy head branch name to clipboard

Conversation

@hbrooks

@hbrooks hbrooks commented May 28, 2026

Copy link
Copy Markdown

Originally PR microsoft#63440 in microsoft/TypeScript by @creazyfrog

…ariant is tried first

Fixes microsoft#7014. When TypeScript resolves overloads it picks the first matching one.
The `reduce(callbackfn, initialValue: T): T` overload was listed before
`reduce<U>(callbackfn, initialValue: U): U`, so `arr.reduce((acc, x) => ..., [])` inferred
`T[]` instead of the expected `U`. Moving the generic `<U>` overload above the `T`-with-initialValue
overload makes TypeScript try the more-specific version first. Applied to all four groups:
ReadonlyArray.reduce, ReadonlyArray.reduceRight, Array.reduce, Array.reduceRight.

Signed-off-by: creazyfrog <rohitcse.gec@gmail.com>
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

Morty Proxy This is a proxified and sanitized view of the page, visit original site.