0

I am using below code using ramda in typescript and it keeps showing error that type is not matching:

R.pipe(R.drop(2), R.dropLast(5))("hello world");

TS2769: No overload matches this call.   The last overload gave the following error.     Argument of type '{ (xs: string): string; (xs: readonly unknown[]): unknown[]; }' is not assignable to parameter of type '(x0: readonly unknown[], x1: unknown, x2: unknown) => string'.       Types of parameters 'xs' and 'x0' are incompatible.         Type 'readonly unknown[]' is not assignable to type 'string'.

How should fix this?

SeyyedKhandon
  • 5,197
  • 8
  • 37
  • 68

1 Answers1

2

It seems the type inference needs a bit of extra help to let it know that you want the type narrowed to a string.

e.g.

R.pipe<string, string, string>(R.drop(2), R.dropLast(5))("hello world")
// or
R.pipe(R.drop(2) as (str: string) => string, R.dropLast(5))("hello world")
Scott Christopher
  • 6,458
  • 23
  • 26
  • It's strange, why do we need to do this? why typescript can't figure it out? – SeyyedKhandon May 26 '20 at 12:05
  • 2
    I suspect it is the combination of the various possible type signatures of `pipe` combined with the `drop` functions that can take either a list or a string. For example, `R.drop(2, R.dropLast(5, "hello world"))` type-checks with no errors. – Scott Christopher May 26 '20 at 22:59