【发布时间】:2021-01-01 18:19:29
【问题描述】:
我想使用扩展运算符从 fp-ts 调用 pipe function,但它没有为此过载。
相反,我不得不将 pipe 强制转换为 any,这看起来很难看,并且会损害可读性。
我可以扩充现有类型吗?
我创建了这个简单的例子,这里是codesandbox。现实世界的例子让我无法确切知道我将传递多少个参数给管道。
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);
【问题讨论】:
标签: typescript fp-ts