Skip to content
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

Variants of R.map() and lost types #121

Open
hastebrot opened this issue Dec 18, 2016 · 4 comments
Open

Variants of R.map() and lost types #121

hastebrot opened this issue Dec 18, 2016 · 4 comments

Comments

@hastebrot
Copy link

hastebrot commented Dec 18, 2016

For the partial applied variants of R.map() the TypeScript compiler fails to infer/resolve the types of the parameter, e. g. elem in the code example below.

import * as R from "ramda"

const array = [1, 2]
R.map(elem => elem, array) // (parameter) elem: number
R.map(elem => elem)(array) // (parameter) elem: {}

Here are the type declarations from @types/ramda:

map<T, U>(fn: (x: T) => U, list: T[]): U[];
map<T, U>(fn: (x: T) => U, obj: Functor<T>): Functor<U>; // used in functors
map<T, U>(fn: (x: T) => U): (list: T[]) => U[];

I quickly tried the declarations from the master branch. But they also didn't work.

I guess there are some issues in this repository related to this problem. I also wonder, if there is an issue on Microsoft/TypeScript related to this.

@KiaraGrouwstra
Copy link
Member

Thank you for posting. This is a variant of several other issues posted here, and comes down to currying/composition failing with functions using generics (yes, in Ramda that's almost all of them). I made a thread about this at TypeScript here. This is the primary problem for our repo right now, and I'd really like a solution for this as well.

@hastebrot
Copy link
Author

hastebrot commented Jun 15, 2017

This still doesn't work with typescript@next (2.5.0-dev.20170615), which includes the TypeScript PRs:

  • Infer from generic function return types
  • Contextual generic function types
  • Stricter generic signature checks

Will this eventually work, or is there a problem with type inference because the types are "flowing from right to left"?

Probably related: microsoft/TypeScript#15680 (comment)

Versions: ramda 0.24.1, @types/ramda 0.0.12.

@KiaraGrouwstra
Copy link
Member

They didn't fix it, see microsoft/TypeScript#16072

We currently infer (x: {}) => { p: {}[] }, but ideally we'd infer (x: A) => { p: A[] }. That's next on the list.

@KiaraGrouwstra
Copy link
Member

I'm thinking the issue could potentially be worked around with given type level calls (microsoft/TypeScript#17961). Not working yet but at least that reduces those two issues to one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants