Joon
Joon

Reputation: 9874

How to write a flowtype for arrow function with generic type

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

Upvotes: 22

Views: 8761

Answers (1)

Sam Goldman
Sam Goldman

Reputation: 1446

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

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

Upvotes: 42

Related Questions