typed-typings / npm-ramda

TypeScript's type definitions for Ramda
MIT License
384 stars 64 forks source link

type into in typescript #441

Open codingedgar opened 5 years ago

codingedgar commented 5 years ago

Hi! first, thank you all for this superb library!

I loooove transducers, so i'm usually using transducer or into everywhere i can, but in typescript land, it has been very hard for me to type it, i would like to understand both how could type it and if it is not possible where is the issue.


import {
  filter,
  into,
  map,
  compose,
} from 'ramda';

type OrderAndValue = { order: number, value: string }

type Values = string[]

const vals: Values = into<any>(
  [],
  compose<any, any, any>(
    filter<any>(x => x.id > 5),
    map<any, any>(x => x.val)
  ),
  [
    { order: 1, value: 'a' },
    { order: 5, value: 'b' },
    { order: 10, value: 'c' },
  ]
)

here, for typescript is so difficult to understand what gets into map, because transducer expects to apply the fns in compose in the read order.

My question: is there any way to type this ? to get the type of OrderAndValue in the map and return Values ?