ES6 Promise / Typescript and the Bluebird Promise

前端 未结 2 1084
悲哀的现实
悲哀的现实 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:49

    I was dealing with

    TS2322: Type 'Bluebird' is not assignable to type 'Promise'. Property '[Symbol.toStringTag]' is missing in type 'Bluebird'.

    and found this thread: https://github.com/DefinitelyTyped/DefinitelyTyped/issues/10801

    The TL;DR; version of it is to do one of the following:

    1. In each of your .ts entry files add the following to overwrite the global promise:

      import * as Bluebird from 'bluebird';

      declare global { export interface Promise extends Bluebird {} }

    Or

    1. wrap all promises in a Bluebird promise constructor. There is some runtime overhead here and it is listed as an anti pattern on Bluebird's site.

    As an aside, I could not get the second option to work, but the first worked fine for me.

提交回复
热议问题