Skip to content

Type errors for Ramda cookbook methods mapKeys and renameBy #273

@mtpultz

Description

@mtpultz

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 on fn argument of the anonymous function.

Example

    import * as R from 'ramda';
    
    export const mapKeys = R.curry(
      (fn: ???, obj: { [k: string]: any } | { [k: number]: any }) =>
        R.fromPairs(
          R.map(
            R.adjust(fn, 0), // <--- Error: tried typings for `adjust`
            R.toPairs(obj) // Fixed by referencing typings of `toPairs`
          )
        )
    );

Error

Error is on fn:

Argument of type '{}' is not assignable to parameter of type '(a: string) => string'. Type '{}' provides no match for the signature '(a: string): string'.

Description

As you would expect you can solve similar issues like with obj by referencing the toPairs typings of { [k: string]: any } | { [k: number]: any }, but I tried using the adjust typings for fn of (a: any) => any with no luck.

A similar typings error occurs for another Ramda cookbook method renameBy that also uses adjust, so I thought maybe this was a typings issue with adjust, but the example below works.

R.adjust((a: any): any => {
  return 2;
}, 2);

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions