New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
bluebird 3.0 definifion is not assignable to ES6 Promises #11027
Comments
Whole error:
I am using |
Ah I see... I believe it's due to this line missing here. This means with the current typings you have to return the same type In the meantime you should probably split up your The alternative is that you could manually specify the generic parameter .then<SomeType>(() => new SomeType(), (err) => 123); // This is an explicit error because SomeType != number to ensure that you return the same type from both callbacks. |
@lhecker but I don't even use // module 1. Note that bluebird is not imported
export default function<T>(promise: Promise<T>) {} // es6 promise used here
// module 2.
import Promise from "bluebird"
import handler from "./module1"
const promise: Promise<any>
handler(promise) // <-- error is here |
Seems that it could be fixed by adding yet another |
Ah damn... sorry. I guess I should finally take a break. 😅 So ignore my comments about what to do in the meantime: Since they are missing anyways and since I really don't or at least "should not" have the time for doing anything besides basic support like this, it'd be greatly appreciated if you could send PRs to add those typings to both projects. 😊 |
@lhecker done :) |
Just a side note, but I always recommend using |
@blakeembrey using |
Unfortunately the Promise typings have changed in TS version 2 and so these typings no longer correspond: https://github.com/Microsoft/TypeScript/blob/070aa83cc06b2974639bbefcde98e6e2fb5fe693/src/lib/es2015.promise.d.ts Can we re-open this issue? |
Any updates on this? |
@OliverJAsh @arg20 could you guys provide self-reproduceable test case of your issue? |
@Strate here you have my error. Using typescript 2.0.3 (lib.es6.d.ts) and @types/bluebird v3.0.33
|
Trying to cast the Bluebird Promise to an ES6 promise throws the following (
|
adding this as proposed in #10831 worked for me readonly [Symbol.toStringTag]: 'Promise'; also, converting to a ES6 Promise did the trick
|
@jmendiara as stated in #10831, there is no |
Just ran into issue when bluebird's promise is not assignable to standard one. And in my case it is impossible to cast bluebird to standard with |
Any updates on this? |
Glad I found this thread. Thought I was going nuts. Would really like to see a fix for this. I described my problem specifics on SO |
I'm running into this issue with @types/bluebird 3.5.3 and TypeScript 2.2.2. |
@silentorb I have got this working by using the
The above works for node environment (I'm using 6.10.x). If you're using webpack then you may need to use something like expose-loader. |
@ksnyde: I previously tried out |
@silentorb the key is to override the global Promise reference; works without issue for me. That said, it certainly would be nice if it just worked out of the box but there's no need to wait with this solution. |
Any progress on this? |
@flyingsky (et. al.) First of all I'd like to remind everyone again that it will never ever be possible to directly assign native Promises to Bluebird ones, since Bluebird promises provide extensions which do not exist in the native implementation. Assigning Bluebird promises to native ones on the other hand should be possible and rightly so. But many here are under the impression that this should just work right now, which definitely is not the case. The reason for this is that while Bluebird exposes all commonly known functions in a native compatible way, it does not expose one particular field: The const p: any = getPromise();
return <Promise>p; This is technically type unsafe and incorrect.
If anyone in this issue wants to see progress I kindly suggest opening a PR for the already mentioned Bluebird issue: petkaantonov/bluebird#1277 |
Looks like this PR has been created: petkaantonov/bluebird#1421 |
@ksnyde – Your import * as Promise from 'bluebird'
global.Promise = Promise Otherwise I get Thank you. |
I'm using
Adding this line fixes the issue https://github.com/DefinitelyTyped/DefinitelyTyped/pull/10831/files Is there any way to fix it locally without modifying bluebird's typings? |
+1 |
@gdpaulmil Thanks for your constructive comment! It prompted me to take a look at the state of affairs over at Bluebird. This in turn means this problem can be fixed right away by resubmitting #10831. One will only have to swap out |
Hey, I'd just like to let you all know that this issue has been fixed in v3.5.27 of P.S.: Thanks again @JoshuaKGoldberg for dealing with the Bluebird PR. 🙂👍 |
Is:
Still applicable for es2017? |
Except for all the other packages that have the previous version as a dependency and didn't get the memo... request-promise, knex,... you just broke a lot of code with this update. The Typescript compiler is throwing nonsense errors all over the place, Typescript 3.3, 3.4, 3.5... doesn't seem to matter. |
If it helps anyone, as mentioned higher up I had the easiest time just NOT swapping my global Promise object out for BB. I haven't encountered any issues where one thing was compatible with another thing. |
@jacklinton I'm sure you are already aware that unit tests are in place to verify that all affected packages still build with the given TypeScript version without "throwing nonsense errors". |
It's difficult to know where to begin, but with all other packages up to date |
This error does sound as if you got two versions of knex 0.17.3 depends on the newest 3.5.27 version of the |
Thanks for being responsive @lhecker . I didn't mean to sound critical, I apologize. You've clearly been working hard on this and it's something we've all been waiting a long time for. Thanks for your hard work getting this update out so quickly after Bluebird made the change. I'll get this bloated monolith to work the way it's supposed to one way or another. |
…Typed#11027) (DefinitelyTyped#34805) * [bluebird] Rename import to Bluebird for tests * [bluebird] Restore assignability to native Promises * [bluebird] Upgrade TypeScript Versions of all dependents
@lhecker can you please republish your request-promise-sample because it seems to be gone. 😢 @VictorioBerra the trick with import * as Promise from 'bluebird';
global.Promise = require('bluebird'); gives me to following error on Node.js 12:
I am using TypeScript v3.7.4, bluebird v3.7.2 and @types/bluebird-global v3.5.12. |
@bennyn I don't have the code anymore. I'm very sorry. I deleted it after the request-promise issue was fixed. |
I'm having the same error as @bennyn , with the latest versions of all bluebird, @types/bluebird-global and TypeScript |
It seems the only viable option with current version of Bluebird 3.7.2 and TypeScript 3.6 is not to use Bluebird typings at all. At the app entrypoint I replace native Promise constructor with Bluebird and use Bluebird using native promise API after that:
|
I personally, frankly, believe that you guys are doing something wrong on your end. 😖
That said, this issue has been closed and should not be used for continued off-topic discussions. |
@lhecker Installing Modified project can be found here: |
@chebum Your comment above didn't make clear that you're trying to type async functions as ones returning a If you'd like to waive a little bit of your type safety you can do the following though:
If you hit any |
The bluebird 3.0 definition is not assignable to standard es6 Promise definition:
/cc @lhecker
The text was updated successfully, but these errors were encountered: