Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

transduce's accumulator type #33

Open
WPitak opened this issue May 22, 2023 · 1 comment
Open

transduce's accumulator type #33

WPitak opened this issue May 22, 2023 · 1 comment

Comments

@WPitak
Copy link

WPitak commented May 22, 2023

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.

@Harris-Miller
Copy link
Collaborator

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

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

No branches or pull requests

2 participants