How to write a flowtype for arrow function with generic type

Joon picture Joon · Jun 4, 2016 · Viewed 7.4k times · Source

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]);

Answer

Sam Goldman picture Sam Goldman · Jun 6, 2016
const fn = <T>(array: Array<T>): Promise<T> => Promise.resolve(array[0]);

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