-
Notifications
You must be signed in to change notification settings - Fork 89
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Pipe typings not seeming to work.. #466
Comments
|
For now I have to use Why rambda cannot use types from |
R.pipe and R.compose typings are taken directly from R.map/R.filter typings issue is mostly due to the fact that the methods supports objects. Generally I agree with the notion that Typescript definitions of Rambda is far from decent, especially when used with R.pipe/R.compose. This is not the first time the issue is brought to my attention and every time I point to Proposal: Variadic Kinds -- Give specific types to variadic functions. If you ask Ramda developers about Typescript, they most likely will decline discussion as they reached consensus that in the current state of Typescript, function library like Ramda is hard to be described. That is the reason why I also was disappointed, when I realized that I cannot use properly R.compose with Typescript. I can say that forced me to change the way I write my Typescript/Javascript code. The problem is that to properly use R.compose, you have to write something like: // pseudo code written on the fly
const result = R.compose<number[], string, number, string[]>(
R.map(String),
R.map(Number),
R.map(String)
)([1,2,3,4]) Without I will look into any wrong typings of Ramda, as long as I am provided with example which proves that the problem is missing in To do that, you need to edit any import * as R from 'ramda'
import {pipe, take, append} from 'rambda'
describe('bug', () => {
it('R.pipe', () => {
const result = pipe(take(5), append(10))([0,1,2,3,4,6])
result // $ExpectType number[]
const ramdaResult = R.pipe(R.take(5), R.append(10))([0,1,2,3,4,6])
ramdaResult // $ExpectType number[]
})
}) Now you need to run If indeed the issue is solely in Rambda typings, then As for Actually I started using |
I just changed the typings of import * as R from 'ramda'
describe('Ramda.flip', () => {
it('function with arity of 2', () => {
const subtractFlipped = R.flip(R.subtract)
const result = subtractFlipped(1, 7)
const curriedResult = subtractFlipped(1)(7)
curriedResult // $ExpectType number
// This is wrong
// ============================================
result // $ExpectType (y: number) => number
})
}) As you can see, like it or not, there is definitely a price to pay when using Typescript with Ramda/Rambda. |
When I wrote about broken pipe and compose typings I meant number of functions not about argument types. See https://github.com/DefinitelyTyped/DefinitelyTyped/blob/7df04df6a1a83df5c73bd4e35f824e09099dfeeb/types/ramda/index.d.ts#L1411 |
@farwayer I understand it the other way, that's why I was a bit excessive in my explanation. Thank you for the clarification. |
@selfrefactor can at least rambda's types for Currently rambda can't even handle more than 1 argument - there are only typings for which makes these functions unusable with typescript... |
@falkenhawk Thank you for bringing this up - it is error of the build step as Rambda.compose has all |
Should be fixed with |
@selfrefactor I still could not use
was causing
so I figured this workaroud... import * as rambda from 'rambda';
// workaround for error TS2554: Expected 0 arguments, but got X.
// https://github.com/microsoft/TypeScript/issues/29904
// https://github.com/selfrefactor/rambda/issues/466
declare module 'rambda' {
function compose<V extends any[], T1>(fn0: () => T1): (...args: V) => T1;
function compose<V extends any[], T1, T2>(fn1: (x: T1) => T2, fn0: () => T1): (...args: V) => T2;
function compose<V extends any[], T1, T2, T3>(fn2: (x: T2) => T3, fn1: (x: T1) => T2, fn0: () => T1): (...args: V) => T3;
function compose<V extends any[], T1, T2, T3, T4>(fn3: (x: T3) => T4, fn2: (x: T2) => T3, fn1: (x: T1) => T2, fn0: () => T1): (...args: V) => T4;
function compose<V extends any[], T1, T2, T3, T4, T5>(fn4: (x: T4) => T5, fn3: (x: T3) => T4, fn2: (x: T2) => T3, fn1: (x: T1) => T2, fn0: () => T1): (...args: V) => T5;
function compose<V extends any[], T1, T2, T3, T4, T5, T6>(fn5: (x: T5) => T6, fn4: (x: T4) => T5, fn3: (x: T3) => T4, fn2: (x: T2) => T3, fn1: (x: T1) => T2, fn0: () => T1): (...args: V) => T6;
function pipe<V extends any[], T1>(fn0: () => T1): (...args: V) => T1;
function pipe<V extends any[], T1, T2>(fn0: () => T1, fn1: (x: T1) => T2): (...args: V) => T2;
function pipe<V extends any[], T1, T2, T3>(fn0: () => T1, fn1: (x: T1) => T2, fn2: (x: T2) => T3): (...args: V) => T3;
function pipe<V extends any[], T1, T2, T3, T4>(fn0: () => T1, fn1: (x: T1) => T2, fn2: (x: T2) => T3, fn3: (x: T3) => T4): (...args: V) => T4;
function pipe<V extends any[], T1, T2, T3, T4, T5>(fn0: () => T1, fn1: (x: T1) => T2, fn2: (x: T2) => T3, fn3: (x: T3) => T4, fn4: (x: T4) => T5): (...args: V) => T5;
function pipe<V extends any[], T1, T2, T3, T4, T5, T6>(fn0: () => T1, fn1: (x: T1) => T2, fn2: (x: T2) => T3, fn3: (x: T3) => T4, fn4: (x: T4) => T5, fn5: (x: T5) => T6): (...args: V) => T6;
function pipe<V extends any[], T1, T2, T3, T4, T5, T6, T7>(fn0: () => T1, fn1: (x: T1) => T2, fn2: (x: T2) => T3, fn3: (x: T3) => T4, fn4: (x: T4) => T5, fn5: (x: T5) => T6, fn6: (x: T6) => T7): (...args: V) => T7;
function pipe<V extends any[], T1, T2, T3, T4, T5, T6, T7, T8>(fn0: () => T1, fn1: (x: T1) => T2, fn2: (x: T2) => T3, fn3: (x: T3) => T4, fn4: (x: T4) => T5, fn5: (x: T5) => T6, fn6: (x: T6) => T7, fn7: (x: T7) => T8): (...args: V) => T8;
function pipe<V extends any[], T1, T2, T3, T4, T5, T6, T7, T8, T9>(fn0: () => T1, fn1: (x: T1) => T2, fn2: (x: T2) => T3, fn3: (x: T3) => T4, fn4: (x: T4) => T5, fn5: (x: T5) => T6, fn6: (x: T6) => T7, fn7: (x: T7) => T8, fn8: (x: T8) => T9): (...args: V) => T9;
function pipe<V extends any[], T1, T2, T3, T4, T5, T6, T7, T8, T9, T10>(fn0: () => T1, fn1: (x: T1) => T2, fn2: (x: T2) => T3, fn3: (x: T3) => T4, fn4: (x: T4) => T5, fn5: (x: T5) => T6, fn6: (x: T6) => T7, fn7: (x: T7) => T8, fn8: (x: T8) => T9, fn9: (x: T9) => T10): (...args: V) => T10;
} |
@falkenhawk Can you give me more detailed example than |
@selfrefactor would this reproduction be enough? 🤔 https://codesandbox.io/s/relaxed-moore-9wf1n?file=/src/index.ts |
It is enough, but I don't see a problem that Typescript complains, as I believe that it should:
this code works:
I am open to accept your suggestion, but I will need a stronger use case than you initially suggested. Also, in the case of |
Actually, it might be only our case where we use I may try to set up a reproduction, but it's quite convoluted in our real code with the different arguments, overloads and return types of those "resolver enhancers" of ours... and a simple example I came up quickly with works just fine: https://codesandbox.io/s/relaxed-moore-9wf1n?file=/src/index2.ts It may also turn out that there is an issue on our side with typings or another typescript issue with e.g. handling union types, maybe something along the lines of microsoft/TypeScript#29904 |
And thanks for the tip about mismatching "inputs", you are right I was passing something - what the individual functions did not expect - to the combined function and that's why the typescript rightfully complained in that simple example. There is just a little something that triggers typescript to yell at me in my real code 🙈 and the "workaround" posted by me may have only accidentally "fixed" it by disabling some ts checks. |
Glad to be able to help. |
typescript: 3.9.3
rambda: 5.4.3
R.pipe<number[]>( shuffle, R.take(5), R.append(10), shuffle, )([0,1,2,3,4,6]) }
With the above code I get the following error:
Expected 1 arguments, but got 4
Please can someone point out to me what im doing wrong?
The text was updated successfully, but these errors were encountered: