ramda/types

transduce's accumulator type

Opened this issue · 1 comments

I was having an issue with type checker complaining about incompatible input type of accumulator on when trying to use transduce to create function transforming array of values into representation of table rows.

After some investigation, I found what I believe to be a bug in definitions in transduce.d.ts.
When transduce is used as 4-ary and unary function, type V seems to be intended as type of accumulator:

export function transduce<T, U, V>(
  xf: (arg: readonly T[]) => U[],
  fn: (acc: V, val: U) => V,
  acc: V,
  list: readonly T[],
): V;
export function transduce<T, U, V>(
  xf: (arg: readonly T[]) => U[],
): (fn: (acc: V, val: U) => V, acc: V, list: readonly T[]) => V;

but when used as binary and ternary function, accumulator has type readonly T[]:

export function transduce<T, U, V>(
  xf: (arg: readonly T[]) => U[],
  fn: (acc: V, val: U) => V,
): (acc: readonly T[], list: readonly T[]) => V;
export function transduce<T, U, V>(
  xf: (arg: readonly T[]) => U[],
  fn: (acc: V, val: U) => V,
  acc: readonly T[],
): (list: readonly T[]) => V;

Shouldn't they be of type V instead?

Edit: For reference this was on version 0.29.1.

It's been like that since we migrated all the types over from @types/ramda. Sure it was just an oversight from whomever created the type back then. Will try and get this updated for you