Skip to content
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

Generated async / await code is missing require statement #5998

Closed
dbaeumer opened this issue Dec 8, 2015 · 3 comments
Closed

Generated async / await code is missing require statement #5998

dbaeumer opened this issue Dec 8, 2015 · 3 comments
Labels
Fixed A PR has been merged for this issue

Comments

@dbaeumer
Copy link
Member

dbaeumer commented Dec 8, 2015

The generated JS code is missing a dependency onto the references promise implementation. Steps to reproduce:

  • install bluebird promises
  • create the following bluebird.d.ts.
declare module 'bluebird' {
    interface Promise<T> {
        then<U>(onFulfilled: (value: T) => U, onRejected: (reason: any) => U): Promise<T>;
    }

    var Promise: {
        new<T>(resolver: (resolve: (value: T) => void, reject: (reason: any) => void) => void): Promise<T>;
    }   
}
  • create a test file
import * as bluebird from 'bluebird';

async function firstName(): bluebird.Promise<string>  {
    return "Dirk";
}

async function lastName(): Promise<string> {
    return "Baeumer";
}

async function use() {
    var first = await firstName();
    var last = await lastName();
    return `${first} ${last}`;
}

if (require.main === module) {
    var p = use();
    p.then((value) => console.log(value));
}
  • compile and run.

Observe: you get an exception. Problem is that the generated code is missing a

var  bluebird = require('bluebird');

statement.

@dbaeumer dbaeumer changed the title async / await drop require statement Generated async / await code is missing require statement Dec 8, 2015
@mhegazy
Copy link
Contributor

mhegazy commented Dec 8, 2015

I believe this is fixed in latest, @DickvdBrink can you give typescript@next a try?

@mhegazy mhegazy added the Fixed A PR has been merged for this issue label Dec 8, 2015
@mhegazy mhegazy added this to the TypeScript 1.8 milestone Dec 8, 2015
@mhegazy mhegazy closed this as completed Dec 8, 2015
@DickvdBrink
Copy link
Contributor

@mhegazy, I definitely can but you probably mean @dbaeumer ;)

@mhegazy
Copy link
Contributor

mhegazy commented Dec 8, 2015

yes. sorry @DickvdBrink.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Fixed A PR has been merged for this issue
Projects
None yet
Development

No branches or pull requests

3 participants