我有一個通用功能:
function hello<T>(n: number, s: string, thing: T): Array<T> {
return [thing]
}
const result = hello(1, 'string arg', 'generic arg')
result具有string[]預期的型別。
但是,如果我咖喱它:
function hello<T>(n: number, s: string, thing: T): Array<T> {
return [thing]
}
const fun1 = curry(hello)(1, 'string arg')
const result = fun1('generic arg')
result現在有型別unknown[]。
如何在保持型別的同時在 Ramda 中使用通用函式?我正在使用 Ramda 0.27.1
uj5u.com熱心網友回復:
R.curry帶有 3 個引數的簽名是:
curry<T1, T2, T3, TResult>(fn: (a: T1, b: T2, c: T3) => TResult): CurriedFunction3<T1, T2, T3, TResult>;
如您所見,您需要手動鍵入curried函式(代碼和框):
function hello<T>(n: number, s: string, thing: T): Array<T> {
return [thing];
}
const fun1 = curry<number, string, string, string[]>(hello)(1, 'string arg');
const result = fun1('generic arg');
console.log(result);
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/439044.html
