最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Flow type for function that return function - Stack Overflow

programmeradmin11浏览0评论

From flow's function type docs, function that return primitive type is like this

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)
}

From flow's function type docs, function that return primitive type is like this

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)
}
Share Improve this question asked Oct 27, 2017 at 17:47 FerryFerry 3402 silver badges12 bronze badges 4
  • 1 Create a delegate and you can use it the same way. – Erick Stone Commented Oct 27, 2017 at 17:49
  • @ErickStone sorry, but I don't have a clue for it. May provide an example? – Ferry Commented Oct 27, 2017 at 18:37
  • blog.slaks/2011/07/… This covers the basics. – Erick Stone Commented Oct 27, 2017 at 19:17
  • 2 e.g. const f = (x :number) : (number => number) => y => x + y – user6445533 Commented Oct 27, 2017 at 19:51
Add a ment  | 

1 Answer 1

Reset to default 7

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.

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/try

发布评论

评论列表(0)

  1. 暂无评论