Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typescript/9.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/195.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
Javascript Lodash将curry与bind一起使用会导致键入脚本错误_Javascript_Typescript_Lodash - Fatal编程技术网

Javascript Lodash将curry与bind一起使用会导致键入脚本错误

Javascript Lodash将curry与bind一起使用会导致键入脚本错误,javascript,typescript,lodash,Javascript,Typescript,Lodash,我试图将bind方法与curry一起使用,但它给了我一个类型错误 const curried = curry(this.method.bind(this)); const getSomething = curried(a, b); 从getSomething获取TS错误: 应为0-1个参数,但得到2个 当我不使用bind方法时,它不会抱怨 const curried = curry(this.method); const getSomething = curried(a, b); 问题是,这

我试图将
bind
方法与
curry
一起使用,但它给了我一个类型错误

const curried = curry(this.method.bind(this));
const getSomething = curried(a, b);
从getSomething获取TS错误:

应为0-1个参数,但得到2个

当我不使用bind方法时,它不会抱怨

const curried = curry(this.method);
const getSomething = curried(a, b);

问题是,这是bind的签名:

bind(this: Function, thisArg: any, ...argArray: any[]): any;
因此,函数的
bind
返回值为
any
curry
仍然有效,因为
any
可以转换为任何其他类型,因此使用
curry
声明顺序中的第一个重载,即此重载:

curry<T1, R>(func: (t1: T1) => R, arity?: number): CurriedFunction1<T1, R>;
现在,使用此版本的bind all应该可以正常工作(对于最多有5个参数的函数,但您可以轻松添加更多参数):


谢谢,一如既往的帮助。
function typedThisBind<T1, T2, T3, T4, R>(fn: (t: T1, t2: T2, t3: T3, t4 : T4) => R, thisArg: any) : typeof fn
function typedThisBind<T1, T2, T3, R>(fn: (t: T1, t2: T2, t3: T3) => R, thisArg: any) : typeof fn
function typedThisBind<T1, T2, R>(fn: (t: T1, t2: T2) => R, thisArg: any) : typeof fn
function typedThisBind<T1, R>(fn: (t: T1) => R, thisArg: any) : typeof fn
function typedThisBind<R>(fn: () => R, thisArg: any) : () => R
function typedThisBind(fn: Function, thisArg: any) : any {
    return fn.bind(thisArg);
}
class Foo {
    method(a: number, b: number) {}
    m(){
        const curried = curry(typedThisBind(this.method, this));
        const getSomething = curried(0, 0); // Works as expected.
    }
}