types(collection): reduce* method signatures (#10405)

* types(collection): reduce* method signatures

* test: explicit expect() types

* test: add tests for arbitrary accumulator type

---------

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
This commit is contained in:
René
2024-07-28 14:37:45 +01:00
committed by GitHub
parent bf6761a44a
commit 6b383350a6
2 changed files with 62 additions and 31 deletions

View File

@@ -616,7 +616,15 @@ export class Collection<Key, Value> extends Map<Key, Value> {
* collection.reduce((acc, guild) => acc + guild.memberCount, 0);
* ```
*/
public reduce<InitialValue = Value>(
public reduce(
fn: (accumulator: Value, value: Value, key: Key, collection: this) => Value,
initialValue?: Value,
): Value;
public reduce<InitialValue>(
fn: (accumulator: InitialValue, value: Value, key: Key, collection: this) => InitialValue,
initialValue: InitialValue,
): InitialValue;
public reduce<InitialValue>(
fn: (accumulator: InitialValue, value: Value, key: Key, collection: this) => InitialValue,
initialValue?: InitialValue,
): InitialValue {
@@ -645,6 +653,14 @@ export class Collection<Key, Value> extends Map<Key, Value> {
* @param fn - Function used to reduce, taking four arguments; `accumulator`, `value`, `key`, and `collection`
* @param initialValue - Starting value for the accumulator
*/
public reduceRight(
fn: (accumulator: Value, value: Value, key: Key, collection: this) => Value,
initialValue?: Value,
): Value;
public reduceRight<InitialValue>(
fn: (accumulator: InitialValue, value: Value, key: Key, collection: this) => InitialValue,
initialValue: InitialValue,
): InitialValue;
public reduceRight<InitialValue>(
fn: (accumulator: InitialValue, value: Value, key: Key, collection: this) => InitialValue,
initialValue?: InitialValue,