Skip to content

Type definition for the Array.prototype.reduce() #33031

@ghost

Description

TypeScript Version: 3.5.1

Search Terms: reduce, es5.d.ts

Code

As currently defined in lib/lib.es5.d.ts:

reduce(callbackfn: (previousValue: T, currentValue: T, currentIndex: number, array: T[]) => T): T;
reduce(callbackfn: (previousValue: T, currentValue: T, currentIndex: number, array: T[]) => T, initialValue: T): T;
reduce<U>(callbackfn: (previousValue: U, currentValue: T, currentIndex: number, array: T[]) => U, initialValue: U): U;

It could be extended by

reduce<U>(callbackfn: (previousValue: U, currentValue: T, currentIndex: number, array: T[]) => U): U;

to work properly in the cases, when initialValue is not supplied and a value that results from a reduction has different type from reducing array elements.

Metadata

Metadata

Assignees

No one assigned

    Labels

    QuestionAn issue which isn't directly actionable in code

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions