Using Promise as return type in Flow

Allyl Isocyanate picture Allyl Isocyanate · Aug 2, 2016 · Viewed 18k times · Source

I'm using Flow 0.30.0. I have a function that returns a promise:

function process(callback:Function):Promise {
  return new Promise((r,re) => callback)
}

Flow raises an error, complaining:

function process(callback:Function):Promise {
                                    ^^^^^^^ Promise. Application of polymorphic type needs <list of 1 argument>. (Can use `*` for inferrable ones)

This works in Try Flow, but not locally. Any ideas of the issue?

Answer

mike d picture mike d · Aug 2, 2016

According to the flow changelog there was a change introduced in v0.28.0 which made type arguments explicit. Explicitly setting the return type to Promise<any> should fix your issue.

Alternatively you can set the following flag to false, although this is a temporary flag which will be removed in the future

experimental.strict_type_args=false

https://github.com/facebook/flow/blob/master/Changelog.md#v0280