Nicht Verstehen
Nicht Verstehen

Reputation: 427

Declare a function using a type alias

I would like to declare the type of a function using a type alias. Something like this:

type F = (_: number) => number;

function f:F (a) { return a; }
          ^ Unexpected token :

declare function f:F;
                  ^ Unexpected token :

The reason I want this is that I have a bunch of functions with the same (rather long) type declaration and I'd like to save the typing and improve the clarity.

Is it possible to do this in Flow? If no is there a feature request open for this?

Upvotes: 0

Views: 788

Answers (1)

Nicht Verstehen
Nicht Verstehen

Reputation: 427

I found a satisfactory answer using declare. It's just I had to use declare var instead of declare function (which makes some sense):

type F = (_: number) => number;
declare var f:F;
function f(a) { return a; }

Using :F inline would be ideal, but this is good enough.

Upvotes: 1

Related Questions