Reputation: 18524
I started a new project where I'd like to use TypeScript instead of pure Javascript. I am struggling with the use of Bluebird in conjunction with third party libraries.
See the following example:
import * as Promise from 'bluebird'
private requestPlayerProfile(playerTag:string):Promise<IPlayerProfile> {
const requestOptions = Object.create(this.options)
return this.limiter.schedule(request, requestOptions)
}
The problem: limiter
is an instance of a third party library and limiter.schedule returns a native promise apparently, while I am using the Bluebird promises in the rest of my application. How would I properly handle such cases?
[ts] Type 'Promise' is not assignable to type 'Bluebird'. Types of property 'then' are incompatible.
Upvotes: 4
Views: 3386
Reputation: 11825
@Filipe is interpreting the error message correctly.
this.limiter.schedule(...)
, that type is incompatible with bluebird.Promise<IPlayerProfile>
.limiter.schedule(...)
returns a "vanila", i.e. a native, Promise<IPlayerProfile>
object. You can easily figure it out by going to the source code where schedule(...)
is defined. In my Visual Studio code I use F12 to get there. Notice the precise return type of the object there.bluebird
's promises altogether; orbluebird
one. I have not tried myself, but the following should work: return Promise.resolve(this.limiter.schedule(request, requestOptions))
(see http://bluebirdjs.com/docs/api/promise.resolve.html).I hope it helps.
Upvotes: 3