rjhilgefort
rjhilgefort

Reputation: 464

TypeScript Type Inference For Simple Function Combination

I'm having a tough time with what I would think should be relatively simple. I can't get the types to comes through in trying to do a simple combination of a couple functions. Is there a way to tell TS to figure out the type inference without having to explicitly put something?

import { pipe, map } from 'ramda'

type TODO = unkown

export const mapP = (xf: TODO) => (data: TODO) =>
  pipe(
    map(xf),
    x => Promise.all(x),
  )(data)

I really just want to let map dictate the types for the function and not have to retype them. Thanks in advance!

Upvotes: 0

Views: 50

Answers (1)

Thomas
Thomas

Reputation: 12657

import { pipe, map } from 'ramda'

export const mapP = <T,R>(xf: (value:T) => Promise<R>|R) => (data: T[]): Promise<R[]> =>
  pipe(
    map(xf),
    x => Promise.all(x),
  )(data)

Does this require any explanantions?

Upvotes: 2

Related Questions