Unable to place : TFunctionin your ad function boo(). However, you can test it by writing the no-op operator after that (boo: TFunction);. The only drawback is booruntime evaluation .
Probably the best way to do this is not to worry about explicitly stating what it boois TFunction, but instead just relying on Flow to check it anytime you use boowhere TFunctionexpected.
, : ( )
type ArithmeticOperation = (a: number, b: number) => number;
function add(a: number, b: number): number {
return a + b;
}
function concat(a: string, b: string): string {
return a + b;
}
function fold(array: Array<number>, operation: ArithmeticOperation): number {
return array.reduce(operation);
}
fold([1, 2, 3], add);
fold([1, 2, 3], concat);