Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/clojure/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Typescript 为传递给Ramda的匿名函数正确设置打字脚本类型_Typescript_Typescript Typings_Ramda.js - Fatal编程技术网

Typescript 为传递给Ramda的匿名函数正确设置打字脚本类型

Typescript 为传递给Ramda的匿名函数正确设置打字脚本类型,typescript,typescript-typings,ramda.js,Typescript,Typescript Typings,Ramda.js,我试图找出Ramda cookbook方法的正确类型mapKeys,如果不抛出错误,它将无法传输 问题 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), // <--- Err

我试图找出Ramda cookbook方法的正确类型
mapKeys
,如果不抛出错误,它将无法传输

问题

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)
      )
    )
);
adjust<T>(fn: (a: T) => T, index: number, list: T[]): T[];
adjust<T>(fn: (a: T) => T, index: number): (list: T[]) => T[];
错误出现在
fn

类型为“{}”的参数不能分配给类型为“(a: 字符串)=>字符串'。类型“{}”没有为签名提供匹配项(a: 字符串):字符串'

我可以从
R.adjust
的键入中看出它使用了泛型,我根据错误尝试了
(a:string)=>string
,这应该是正确的键入,以及一些其他变体,例如
(a:string)=>string[]

有人能指出匿名函数的
fn
参数应该是什么来修复打字错误吗

通过使用VSCode将示例粘贴到TypeScript项目中并通过npm安装Ramda,这非常容易复制,我将
R.adjust
的打字作为参考

示例

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)
      )
    )
);
adjust<T>(fn: (a: T) => T, index: number, list: T[]): T[];
adjust<T>(fn: (a: T) => T, index: number): (list: T[]) => T[];
import*as R从'ramda';
导出常量映射键=R.curry(
(fn:?,obj:{[k:string]:any}{[k:number]:any}=>
R.fromPairs(
R.map(
R.adjust(fn,0),//T,索引:number,列表:T[]):T[];
调整(fn:(a:T)=>T,索引:编号):(列表:T[])=>T[];

我在for
types/npm-ramda上发布了一个问题,a被合并到master中,用于下一版本的ramda-typings。

我在for
types/npm-ramda上发布了一个问题,a被合并到master中,用于下一版本的ramda-typings。

我不知道Typescript。但是该函数应该有一个接受的类型这是一个字符串,返回一个字符串。我想理论上它可能与
String||Number
的类型相同,尤其是在返回中,但这可能太过分了。(谁会这样使用呢?@ScottSauyet yah当我看到错误时,我也这么认为,但我已经尝试了错误消息
中提供的内容。)(a:字符串)=>string
,和
string
。我认为这可能是
adjust
打字的问题……因为拉姆达烹饪书
renameBy
中使用
adjust
的另一种方法也有同样的问题。恐怕我不太适合。我不知道TS到底是如何工作的。祝你好运。我不知道Typescript。但是这个函数应该有一个接受单个字符串并返回一个字符串的类型。我想理论上它可能与
String | | Number
的类型相同,尤其是在返回中,但这可能太过分了。(谁会这样使用它?)@ScottSauyet yah当我看到错误时,我也有同样的想法,但我已经尝试了错误消息
中提供的内容(a:string)=>string
,和
string
。我认为这可能是
adjust
打字的问题……因为拉姆达烹饪书
renameBy
中使用
adjust
的另一种方法也有同样的问题。我恐怕我不适合。不知道TS到底是如何工作的。祝你好运。