pbeshai / tidy

Tidy up your data with JavaScript, inspired by dplyr and the tidyverse
https://pbeshai.github.io/tidy
MIT License
725 stars 21 forks source link

Type error when using groupBy after mutate #59

Closed fernandoabolafio closed 2 years ago

fernandoabolafio commented 2 years ago

See the code example here: https://codesandbox.io/s/divine-cache-x3rzjj?file=/src/App.tsx

Basically doing this:

tidy(data, mutate({ ab: (d) => d.a * d.b }), groupBy("ab"));

Results in a Typescript error.

Note: It doesn't matter which argument is passed to groupBy, the error persists either way.

ado387 commented 2 years ago

I found out that you can bypass this error by wrapping mutate and groupBy inside when clause:

tidy(
  data,
  when( true, [ // < don't forget the bracket
    mutate( /* some mutation */ ),
    groupBy( /*some grouping */),
  ]);
);

While this works, I didn't have time to work out why it works, if someone can elaborate that would be great!

pbeshai commented 2 years ago

Should be fixed in 2.5.0+ https://codesandbox.io/s/silly-beaver-db0t60?file=/src/App.tsx