-
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
Type errors for Ramda cookbook methods mapKeys
and renameBy
#273
Comments
mapKeys
and renameBy
Ramda cookbook methodsmapKeys
and renameBy
mapKeys
and renameBy
mapKeys
and renameBy
Typings have trouble with generics, yeah. I tried reminding them this was still an issue at microsoft/TypeScript#16072 (comment). Anyway, glad you liked |
Thanks for the reply @tycho01. Yah definitely find
My TypeScript isn't very strong yet, but from the typings included below for
|
Oh, that makes sense. So what it's saying is if |
Hi @tycho01, thanks for the help. I tried setting By comparison it was easy to get I think this is probably the most confusing thing with TypeScript which is impeding our full adoption of it into Node projects, and in this particular case means not using Ramda in Angular, or Node unless developed using native ES6/7/Next. I almost can't imagine living without type safety, but the time spent doing this is overwhelming since it isn't like a "normal" bug you can just track down. |
@mtpultz: I sympathize. Particularly in functional programming, TypeScript unfortunately may still feel like more of a bolt-on type system than an innately typed language. /cc @ikatyang: his issue appears to be that I can see the intentions w.r.t. type safety though. The most solution seems type-level heterogeneous A short-term solution should involve a cast I guess... |
Thanks for fixing that issue. I was looking at the committed fix out of interest and that is definitely outside my realm of understanding. Is it possible to consume the update on npm, or is microsoft/TypeScript#17884 blocking? |
We're trying to send PRs to DefinitelyTyped, but unfortunately it's blocked, see #233. |
import * as R from 'ramda'
export const mapKeys = R.curry(
(fn: (key: string) => string, obj: { [k: string]: any } | { [k: number]: any }) =>
R.fromPairs(
R.map(
R.adjust<0, [string, any]>(fn, 0),
R.toPairs(obj)
)
)
) So should this work? Getting |
@raine Similar to #377, see #377 (comment). |
I'm trying to figure out what the proper typings are for the Ramda cookbook method
mapKeys
so it will transpile without throwing an error due to typings onfn
argument of the anonymous function.Example
Error
Error is on
fn
:Description
As you would expect you can solve similar issues like with
obj
by referencing thetoPairs
typings of{ [k: string]: any } | { [k: number]: any }
, but I tried using theadjust
typings forfn
of(a: any) => any
with no luck.A similar typings error occurs for another Ramda cookbook method
renameBy
that also usesadjust
, so I thought maybe this was a typings issue withadjust
, but the example below works.The text was updated successfully, but these errors were encountered: