-
Notifications
You must be signed in to change notification settings - Fork 12.5k
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
Async / await with Bluebird promises #8331
Comments
See #6631 which describes the rationale for reserving the identifier |
Thanks! I see that it's unlikely the current behavior would change then... Closing. |
This is horrible but compiles and seems to work:
import * as Bluebird from 'bluebird';
export interface DummyConstructor extends Bluebird<any> {
new<T>(): Bluebird<T>;
all: any;
race: any;
}
declare global {
interface Promise<T> extends Bluebird<T> {}
interface PromiseConstructor extends DummyConstructor {}
} Test code: import * as Bluebird from 'bluebird';
Promise = Bluebird as any;
async function test() {
console.log('Waiting...');
await Promise.delay(1000);
console.log('Done!');
}
test(); Not sure if this is actually valid and whether redefining |
Maybe I'll reopen this to have the above questions looked at, in case others run into the same issue. |
Actually this simpler version compiles and runs fine: Promise = require('bluebird');
async function test() {
await Promise.delay(1000);
}
test(); It simply assigns to the global If you look at the emitted JavaScript, the builtin Since a compliant runtime will always use ES6 Promises for async functions, even if the global |
@yortus Thanks! I've been using typed-typings/npm-bluebird which seems to require the above shim. I guess the conclusion is that there's several ways around the new stricter native ES6 promise requirement, and as long as the code is transpiled to ES6 instead of ES7, it should run the same on all platforms that support generators/ |
In TypeScript 1.9.0-dev.20160426 I tried:
The compiler reports:
error TS2529: Duplicate identifier 'Promise'. Compiler reserves name 'Promise' in top level scope of a module containing async functions.
Especially since this is purely for Node.js, I'd like to use Bluebird promises for their debuggability and import them as
Promise
instead of some other name.Could I provide my own
__awaiter
or could the default one use the importedPromise
?The text was updated successfully, but these errors were encountered: