[英]Flow type for function that return function
From flow's function type docs , function that return primitive type
is like this 从flow的函数类型docs ,返回
primitive type
函数是这样的
const a = aFunc = (id: number): number => id + 1
. const a = aFunc = (id: number): number => id + 1
。
But, how to create flow type for a function that return a function? 但是,如何为返回函数的函数创建流类型?
const aFunc = (id: number): <what type?> => {
return bFunc(a): void => console.log(a)
}
You can either create a separate type, or you can do it inline. 您可以创建单独的类型,也可以内联创建。
Or you can choose to don't specify a return-type at all, because flow
knows the return type of bFunc
. 或者您可以选择根本不指定返回类型,因为
flow
知道bFunc
的返回类型。
const bFunc = (a): void => console.log(a);
Separate type: 单独类型:
type aFuncReturnType = () => void;
const aFunc = (id: number): aFuncReturnType => () => bFunc(id);
Inline: 排队:
const aFunc = (id: number): (() => void) => () => bFunc(id);
You can also see this on flow.org/try 🙂 你也可以在flow.org/try上看到这个
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.