使用类型别名声明函数

时间:2016-10-15 20:58:07

标签: flowtype

我想使用类型别名声明函数的类型。像这样:

type F = (_: number) => number;

function f:F (a) { return a; }
          ^ Unexpected token :

declare function f:F;
                  ^ Unexpected token :

我想要的原因是我有一堆具有相同(相当长)类型声明的函数,我希望保存输入并提高清晰度。

可以在Flow中执行此操作吗?如果没有为此打开功能请求?

1 个答案:

答案 0 :(得分:1)

我使用声明找到了满意的答案。我必须使用declare var代替declare function(这有点道理):

type F = (_: number) => number;
declare var f:F;
function f(a) { return a; }

使用:F内联是理想的,但这已经足够了。

相关问题