selfrefactor/rambda

TypeScript Error while using filter in pipe

diaes opened this issue · 2 comments

diaes commented

Hi!
I have a problem with typing the pipe.
Here is an example:

const list: MyTestType[] = [{ value: 'aaaa' }, { value: 'bbb' }]

  pipe<MyTestType[], MyTestType[]>(filter((x) => x.value.includes('a')))(list)

I got TS error: TS2345: Argument of type '(input: MyTestType[]) => MyTestType[]' is not assignable to parameter of type '(...args: MyTestType[]) => MyTestType[]'.   Types of parameters 'input' and 'args' are incompatible.     Type 'MyTestType' is missing the following properties from type 'MyTestType[]': length, pop, push, concat, and 26 more.

When I remove typing, it works:
pipe(filter((x: MyTestType) => x.value.includes('a')))(list)

But originally my pipe is much more complicated and this typing actually helped. It stop working for version 7.
Could you help me with that?

Sure, I will check. FYI R.pipe/compose typings are following @types/ramda changes

I assume that interface MyTestType{value: string} is missing in your example as you haven't provided it.

I made a test using Ramda and your example fails there as well. Not much I can do about that. It is known shortcoming of TS definitions.

In this context, remeda library does better job than Ramda/Rambda as you can see in this test

test('remeda test', () => {
  interface MyTestType{value:string}
  const list: MyTestType[] = [{ value: 'aaaa' }, { value: 'bbb' }]
  
  let result = createPipe<MyTestType[], MyTestType[]>(filterRemeda((x) => x.value.includes('a')))(list)
  result // $ExpectType MyTestType[]
})

I am closing the ticket as there is not much I can do about it, but feel free to make a comment.