我想使用扩展运算符从 fp-ts 调用管道函数,但它没有重载。
相反,我不得不强制pipe
转换为任何,这看起来很丑陋并且会损害可读性。
我可以扩充现有类型吗?
我创建了这个简单的示例,这里是一个代码框。现实世界的例子让我无法确切知道我将传递多少个参数给管道。
import { pipe } from "fp-ts/function";
const o = { a: "a", b: "b", c: "c" };
type O = typeof o;
type G = (o: O) => O;
const set = (...getters: G[]) => {
/*
Expected 1-20 arguments, but got 0 or more.ts(2556)
function.d.ts(225, 33): An argument for 'a' was not
*/
return pipe(...getters);
// this works but is ugly
// return (pipe as any)(...getters);
};
const getters: G[] = [
(o: O) => ({ ...o, a: "5" }),
(o: O) => ({ ...o, b: "6" }),
(o: O) => ({ ...o, c: "8" })
];
set(...getters);