Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use Bluebird in Typescript 2.1+

(I have read this post but it is from August and it does not answer my question for the current typescript version.)

I'm currently using Typescript 1.8 in my project and this works fine:

import * as Promise from "bluebird";
async function f() : Promise<void> {
  return Promise.delay(200);
}

But if I try to compile with Typescript 2.1:

index.ts(2,16): error TS1059: Return expression in async function does not have a valid callable 'then' member.

Googling the issue of using Bluebird Promises in Typscript, I have also found many github discussions, comments and PRs, but they are all very hard to grasp and while discussing interesting points, I can't find anywhere that says how I'm supposed to get this to work now.

So, how am I supposed to be able to use Bluebird for Promises in Typescript 2.1?

like image 239
Ludwik Avatar asked Dec 28 '16 09:12

Ludwik


1 Answers

Consider using @types/bluebird-global as follows.

npm install --save-dev @types/bluebird-global

Import this once in your main entrypoint.

// The same Promise API, everywhere.
import * as Promise from 'bluebird'
global.Promise = Promise

See DefinitelyTyped issue #11027 for further context.

like image 186
Mikol Graves Avatar answered Sep 19 '22 16:09

Mikol Graves