-
Notifications
You must be signed in to change notification settings - Fork 595
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
include proposed Promise.prototype.finally
#232
Comments
/cc @ljharb I am really unsure about whether you should wait longer. I don't have a lot of confidence in the current spec until tc39/proposal-promise-finally#7 is done and a series of extensive tests are written. But at a glance those semantics are probably what we intend. I guess I would hold off on including this in es6-promise until stage 3 or stage 4. But I dunno, this whole repo's name is a lie (promises are part of every ES, not just ES6, and have seen fixes since ES6; finally is not part of ES6), so it's not clear what the bar is for inclusion. |
@domenic ya, may need a rename as |
While I don't expect any changes, I think waiting for stage 3 would be appropriate. |
@ljharb I'll keep it in a branch, and |
Looking forward to this one boys! |
Promise.prototype.finally [fixes #232]
Warning: Due to incorporating a future spec feature, this pull request breaks compatibility with the global Any time one tries to use a Promise-returning core library function, such as
Could be my skills are lacking, but for now I'm unsure how to circumvent the error other than by pinning my |
@shirakaba this isn't a future spec feature; In other words, if the core TS library lacks a definition for |
Okay, it looks like it may potentially even be a WebStorm IDE issue – Typescript has a lib called WebStorm's language service has most of the TypeScript core libs, but also lacks |
I have now tried adding
interface Promise<T> {
/**
* Attaches a callback that is invoked when the Promise is settled (fulfilled or rejected). The
* resolved value cannot be modified from the callback.
* @param onfinally The callback to execute when the Promise is settled (fulfilled or rejected).
* @returns A Promise for the completion of the callback.
*/
finally(onfinally?: (() => void) | undefined | null): Promise<T>
}
export interface Thenable <R> {
then <U> (onFulfilled?: (value: R) => U | Thenable<U>, onRejected?: (error: any) => U | Thenable<U>): Thenable<U>;
then <U> (onFulfilled?: (value: R) => U | Thenable<U>, onRejected?: (error: any) => void): Thenable<U>;
}
export class Promise <R> implements Thenable <R> {
// ...
finally <U> (onFinally?: (callback: any) => U | Thenable<U>): Promise<U>;
// ...
} I am now receiving a warning that the typings for Impressively, I can get it to seemingly work by merging the two interfaces a bit:
interface Thenable <R> {
then <U> (onFulfilled?: (value: R) => U | Thenable<U>, onRejected?: (error: any) => U | Thenable<U>): Thenable<U>;
then <U> (onFulfilled?: (value: R) => U | Thenable<U>, onRejected?: (error: any) => void): Thenable<U>;
}
/**
* Represents the completion of an asynchronous operation
*/
interface Promise<T> {
/**
* Attaches a callback that is invoked when the Promise is settled (fulfilled or rejected). The
* resolved value cannot be modified from the callback.
* @param onfinally The callback to execute when the Promise is settled (fulfilled or rejected).
* @returns A Promise for the completion of the callback.
*/
finally(onfinally?: (() => void) | undefined | null): Promise<T>
finally <U> (onFinally?: (callback: any) => U | Thenable<U>): Promise<U>;
} ... But who knows what I may have broken downstream..? |
Some options, both kinda bad: Using es6-promise typings alongside core library's typings
{
"compilerOptions": {
"lib": ["DOM","ES5","ScriptHost"]
}
}
// Polyfills es6-promise to the global object.
require('es6-promise').polyfill();
// Gets typings and implementation from "es6-promise" module.
import {Promise} from "es6-promise";
// Works, due to using typings from es6-promise
Promise.race([]).finally();
// Works, due to using typings from core library
navigator.requestMediaKeySystemAccess();
navigator.requestMediaKeySystemAccess()
.then(() => {
// Fails, due to mixing core-library promise chain with
// a 'es6-promise' class function.
Promise.resolve();
})
.catch((e: any) => {})
// Fails: would need to add the "esnext.promise" lib.
.finally(); Relying purely on the core library's typings
{
"compilerOptions": {
"lib": ["DOM","ES5","ScriptHost", "esnext.promise"]
}
}
// Polyfills es6-promise to the global object.
require('es6-promise').polyfill();
// Option 1: Don't import "es6-promise" as a module, because
// it's available via the global Promise object anyway.
// Option 2: Import "es6-promise" as an untyped module, with
// typings inferred from the global core libraries.
const Promise = require("es6-promise");
// (Comment out above line if you don't want to use option 2)
// Works, due to using typings from core library, including esnext.promise
Promise.race([]).finally();
// Works, due to using typings from core library, including esnext.promise
navigator.requestMediaKeySystemAccess().finally();
navigator.requestMediaKeySystemAccess()
.then(() => {
// Works, due to using typings from core library, including esnext.promise
Promise.resolve();
})
.catch((e: any) => {})
// Works, due to using typings from core library, including esnext.promise
.finally(); |
Have just contacted support, and found that WebStorm 2018.1 EAP (v181.4096.25 Early Access Program) supports esnext.promise, so there is no longer any need to add |
Please see my response: https://stackoverflow.com/a/51187968/5951226 |
basically just:
Questions:
es6-promise/auto
polyfill the whole promise, or justfinally
iffinally
is not present?The text was updated successfully, but these errors were encountered: