Higher order function, stream type annotations

I am trying to write some simple, functional examples for evaluating a flow type system. I am missing something obvious or this pattern should work:

function logger (message: string): void {
    console.log(message);
}

function consumer (logFunc: logger) {
    logFunc('foo');
}

consumer(logger);

When I try it on tryflow.org , I get "Signed signature not found in prototype." I get the same message on local start (thread 0.21.0):

  8:     logFunc('foo');
         ^^^^^^^^^^^^^^ function call. Callable signature not found in
  8:     logFunc('foo');
         ^^^^^^^ prototype

I can solve the problem by explicitly declaring the type alias, but this seems like unnecessary duplication (especially for more complex modules):

type loggerType = (message: string) => void;

function logger (message: string): void {
    console.log(message);
}

function consumer (logFunc: loggerType) {
    logFunc('foo');
}

consumer(logger);

The only relevant documentation I have found so far: http://flowtype.org/docs/functions.html#function-based-type-annotations

, consumer logger (, npm) , logger (es6 commonJS).

  • (logger loggerType).
  • logger consumer - , logFunc logger. , .

, ?

+4
1

typeof:

function consumer (logFunc: typeof logger) {
    logFunc('foo');
}

, , , , , , , - .

, . , 15, 1 9

enter image description here

+7

Source: https://habr.com/ru/post/1629070/


All Articles