【发布时间】:2020-01-14 12:53:07
【问题描述】:
我正在尝试注释此作文:
const get1 = (n: number, s: string) => `${n}_${s}`;
const get2 = (s: string, n: number) => `${n}_${s}`;
const foo = (get) => (...args) => {
get(...args);
}
const foo1= foo(get1);
const foo2= foo(get2);
foo1(2, 'qwe');
foo2('qwe', 1)
目前我使用 Flow 作为类型检查器,但我也对 TypeScript 答案感兴趣,因为它可能是我迁移的好点。
【问题讨论】:
-
这是
apply函数,很难以有意义的方式进行注释。因为get可以是具有任何输入和任何输出的任何函数,而...args可以是任何类型,所以apply变为“任何函数和任何参数,产生任何输出”... -
比较一下
const foo = <A, B> (get: A => B, x: A): B => get (x)有一个有意义的注解
标签: javascript typescript types flowtype