Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to write a flowtype for arrow function with generic type

Tags:

flowtype

How do I write flowtype for the following code?

The function argument is an array of generic type.

const fn = (array) => Promise.resolve(array[0]);
like image 705
Joon Avatar asked Jun 04 '16 02:06

Joon


1 Answers

const fn = <T>(array: Array<T>): Promise<T> => Promise.resolve(array[0]); 

Relevant documentation: https://flow.org/en/docs/types/generics/

like image 98
Sam Goldman Avatar answered Sep 19 '22 13:09

Sam Goldman