【发布时间】:2021-12-05 02:31:31
【问题描述】:
juxt 调用一个函数数组来返回一个值数组。文档:ramdaclojure
我正在尝试键入没有覆盖的数据优先版本,但我不知道如何map the tuple of functions to their return values。这就是我所拥有的:
type JuxtFn<T> = (x: T) => any
function juxt<T, Fs extends JuxtFn<T>[]>(
x: T,
fns: Fs,
): {[K in keyof Fs]: ReturnType<Fs[K]>} {
return fns.map(fn => fn(x))
}
它抱怨(以及其他抱怨)
Type 'Fs[K]' does not satisfy the constraint '(...args: any) => any'.
这在 TypeScript 中可行吗?
【问题讨论】:
标签: typescript typescript-generics ramda.js