ES6 Promise / Typescript and the Bluebird Promise

前端 未结 2 1085
悲哀的现实
悲哀的现实 2021-02-19 05:11

I have a nodejs / typescript 2 project and use the es6-promise package. Now i would like to get rid of the extra package because i can target ES6 in typescript directly.

2条回答
  •  情深已故
    2021-02-19 05:47

    Since there is no [Symbol.toStringTag] in Bluebird, it's incompatible indeed. There are other things that differ Bluebird implementation from native Promise - scheduler, error handling... The correct way to handle this is:

    const promise: Promise = Promise.resolve(bluebirdPromise);
    

    If runtime compatibility is not an issue for sure, this can be addressed with type casting only in relatively type-safe manner:

    const promise: Promise = >>bluebirdPromise;
    

    or

    const promise: Promise = >>bluebirdPromise;
    

提交回复
热议问题