It doesn't appear to work (for TypeScript v1.4 is ok instead):
/* @flow */
var f = (x: number) => x * 2; // Flow Error: "Invalid left-hand side in formals list"
var f = (x: number): number => x * 2; // Flow Error: "Unexpected token :"
FWIW, this does work:
/* @flow */
var f: (x: number) => number = x => x * 2; // ok
% flow --version
Flow, a static type checker for JavaScript, version 0.4.0
This is a duplicate of #37
Hi @gcanti - per @samwgoldman this is on the todo list. Thanks!
This has been fixed since 0.12. Thanks for the report!
Just a quick question - how exactly should I type the parameters and the returning type of the arrow function? As in the @gcanti original example?
Everything in @gcanti's original post should work now. Arrow functions that surround their parameters with parenthesis put parameter type annotations after the parameters and return type annotations after the parens. Type parameters go before the parens, like var identity = <T>(x: T): T => x.
We disallow x: number => x * 10 since it's ambiguous if the annotation is for the parameter type or return type.
Thanks! I couldn't find it anywhere.
Most helpful comment
Everything in @gcanti's original post should work now. Arrow functions that surround their parameters with parenthesis put parameter type annotations after the parameters and return type annotations after the parens. Type parameters go before the parens, like
var identity = <T>(x: T): T => x.We disallow
x: number => x * 10since it's ambiguous if the annotation is for the parameter type or return type.