简体   繁体   English

返回功能的功能的流程类型

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM