Skip to content

Generated async / await code is missing require statement #5998

Closed

Description

@dbaeumer

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.

Activity

  1. changed the title [-]async / await drop require statement[/-] [+]Generated async / await code is missing require statement[/+] on Dec 8, 2015
  2. mhegazy commented on Dec 8, 2015

    @mhegazy
    Contributor

    I believe this is fixed in latest, Dick van den Brink (@DickvdBrink) can you give typescript@next a try?

  3. DickvdBrink commented on Dec 8, 2015

    @DickvdBrink
    Contributor

    Mohamed Hegazy (@mhegazy), I definitely can but you probably mean Dirk Bäumer (@dbaeumer) ;)

  4. mhegazy commented on Dec 8, 2015

    @mhegazy
    Contributor
  5. locked and limited conversation to collaborators on Jun 19, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    FixedA PR has been merged for this issue

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions