Flow: Add support for Promise's `.finally()` method.

Created on 13 Feb 2018  路  5Comments  路  Source: facebook/flow

Using the promise method .finally() will break flow's typing. Here's a silly example:

 31:     let test = new Promise(() => {}).finally(() => console.log('test'))
                                          ^^^^^^^ property `finally`. Property not found in
 31:     let test = new Promise(() => {}).finally(() => console.log('test'))
                    ^^^^^^^^^^^^^^^^^^^^^ Promise

Is there a clean way to use the promise method .finally() (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/finally) and not break Flow's typing?

In core.js I see it's not supported on the Promise object: https://github.com/facebook/flow/blob/master/lib/core.js#L591-L610. Is there a particular reason why?

Most helpful comment

Ran into this as well, finally is part of the promise API now, Flow should see it as such

All 5 comments

Does Flow support proposal APIs? You could derive a new class from Promise until it lands in core.js:

declare class PromiseWithFinally<+R> extends Promise<R> {
  finally<U>(onFinally: () => U): Promise<U>;
}

It seems like Promise.prototype.finally is stage 4. I think this means it is a "finished" proposal and should probably be included now in core.js.

Not only is it stage 4, it already is available in the standard releases of both Firefox and Chrome, and Microsoft's ChakraCore has it in the code already (just merged into master 3 days ago).

Ran into this as well, finally is part of the promise API now, Flow should see it as such

Was this page helpful?
0 / 5 - 0 ratings