-
Notifications
You must be signed in to change notification settings - Fork 64
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
Typing for pipe and compose #29
Comments
Yes, Did you try the latest (and current) commit of typescript-ramda? I've tried to improve the ability of |
Yup, I'm on the latest release. I hit against typing errors on
FYI, this does type correctly if I reverse the order and use |
Hmm, I see that |
That would be awesome. Thanks! |
Done, let me know if that doesn't work for you. |
Thanks for this. A bunch of problems have been fixed, but a bunch of new problems have popped up. Here is a strange one:
|
It actually turns out that this can be fixed by applying generics to |
See #31 |
Here is another example of a pipeline which type-checks strangely:
Somehow the |
And another where the return type of
It seems like Typescript somehow loses the type of the previous link in the chain. |
It seems that
This is were Typescript looses its type. This is due to the following
Because T and U in The other example:
works well if you remove the , but only because |
FWIW, I ran into this issue as well - this is where I ran into problems let mapPackages = R.partial(R.map, [test => test.package]);
let filterBuild = R.partial(R.filter, [test => test.build === build]);
let getPackages = R.compose(R.uniq, mapPackages, filterBuild);
this.packages = getPackages(this._tests); TypeScript didn't like my |
@wesleycho If you leave out the R.partials and just use the standard partial application of R.map and R.filter, it works almost perfectly. I added a quick type interface for build/package. interface Foo {
build: string,
package: string
}
const build = 'dev';
let mapPackages = R.map((test: Foo) => test.package);
let filterBuild = R.filter((test: Foo) => test.build === build);
let getPackages = R.compose(R.uniq, mapPackages, filterBuild);
let foos = [{
build: 'dev',
package: 'devPackage'
}, {
build: 'prod',
package: 'prodPackage'
}, {
build: 'dev',
package: 'devPackage'
}];
let foosFiltered = getPackages(foos);
console.log('foosFiltered: ' , foosFiltered); The only catch is that it loses the return type with the let getPackages = R.compose((packages: string[]) => R.uniq(packages), mapPackages, filterBuild); |
|
pipe
/compose
are really the main building blocks of Ramda, and it seems that a lot of the time Typescript doesn't correctly figure out the types from what's in the chain and its necessary to explicitly put the type into the generic. Sometimes even this doesn't work and you have to<any>
the whole pipeline to get it to compile. This isn't a specific issue as such, and I don't have any particular solutions but I just wanted to put it out there:What could we do to improve the typing of
pipe
/compose
?The text was updated successfully, but these errors were encountered: