What is the use of asterisk (*) type in Flow and what is the equivalent of that in TypeScript?

Edit: Since I originally wrote this answer, I have learned that * is unsafe when it appears at module boundaries. I can't recommend using it, and it may be removed in the future.

It just tells Flow to infer a type parameter, rather than making you write it out explicitly:

function foo(): Array<*> {
  return [5];
}

// Flow issues an error:
//    2:   return [5];
//                 ^ number. This type is incompatible with
//    10: (foo(): Array<string>);
//                     ^ string
(foo(): Array<string>);

(try flow)

It is different from any -- any is an unsafe type, so if you replaced * with any in this example, Flow would not give you any errors. You could replace it with number and Flow would give you a similar error.


The asterisk * in Flow tells it to infer the type, which was already answered by Nat Mote

Additionally Typescript has no direct equivalent for the asterisk, and consequently it's unable to be told to infer a type. It does however, like Flow, infer types automatically in some specific cases. TypeScript Type Inference Documentation, Type Inference Examples

Check out unique features on this page: Differences between Flow and TypeScript