Supporting Promise.prototype.finally() in TypeScript (targeting ES5)

`Promise.prototype.finally()` is a stage 4 (finished) proposal for ES2018. TypeScript supports it via the declaration file `lib.esnext.promise.d.ts`: https://github.com/Microsoft/TypeScript/blob/master/lib/lib.esnext.promise.d.ts, importable via `--lib esnext.promise`.

I am using the `es6-promise` library https://github.com/stefanpenner/es6-promise to polyfill Promises, but have to interact with Promises returned from the standard library, eg. by `navigator.requestMediaKeySystemAccess()`. Thus, the global declaration of a Promise must match that of `es6-promise`. Otherwise, the following error will be returned when calling `Promise.resolve()` (where Promise is imported from `es6-promise`) from inside a Promise chain initiated by a core-library function:

Error:(12, 5) TS2719: Type 'Promise<T>' is not assignable to type 'Promise<T>'. Two different types with this name exist, but they are unrelated.
  Property 'finally' is missing in type 'Promise<T>'.

When I add `esnext.promise` to the `libs` section in my `tsconfig.json`, I receive a warning that it is not one of the allowed values. Additionally, `/Applications/WebStorm.app/Contents/plugins/JavaScriptLanguage/jsLanguageServicesImpl/external` does not contain the expected `esnext.promise.d.ts` file.

How should I support `Promise.prototype.finally()`?

0

Please try 2018.1 EAP (https://www.jetbrains.com/webstorm/eap/) - it supports esnext.promise library

1
Avatar
Permanently deleted user

Thank you again Elena! That helps out a lot.

EDIT: This issue can be considered closed.

0

请先登录再写评论。