her-promise
Version:
This is a polyfill of the ES6/ES9/ES11/ES12 Promise.
14 lines (12 loc) • 412 B
text/typescript
import { defineProp, isFunc } from './utils';
defineProp(Promise.prototype, 'finally', function <
T
>(this: Promise<T>, onfinally?: (() => void) | undefined | null): Promise<T> {
return this.then(
value => Promise.resolve(isFunc(onfinally) ? onfinally() : onfinally).then(() => value),
reason =>
Promise.resolve(isFunc(onfinally) ? onfinally() : onfinally).then(() => {
throw reason;
})
);
});