Skip to content

Invalid code generated when namespaced type is used as return type for async function #5333

@okunokentaro

Description

@okunokentaro

tsc 1.6.2 with -t es6 --experimentalAsyncFunctions.

declare namespace ns {
  export type PromiseAlias = Promise<any>;
}

async function f(): ns.PromiseAlias {
  return new Promise((resolve) => {
    resolve();
  });
}

f();

converts to the bellow.

var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promise, generator) {
    return new Promise(function (resolve, reject) {
        generator = generator.call(thisArg, _arguments);
        function cast(value) { return value instanceof Promise && value.constructor === Promise ? value : new Promise(function (resolve) { resolve(value); }); }
        function onfulfill(value) { try { step("next", value); } catch (e) { reject(e); } }
        function onreject(value) { try { step("throw", value); } catch (e) { reject(e); } }
        function step(verb, value) {
            var result = generator[verb](value);
            result.done ? resolve(result.value) : cast(result.value).then(onfulfill, onreject);
        }
        step("next", void 0);
    });
};
function f() {
    return __awaiter(this, void 0, ns.PromiseAlias, function* () {
        return new Promise((resolve) => {
            resolve();
        });
    });
}
f();

throw this error.

return __awaiter(this, void 0, ns.PromiseAlias, function* () {
                               ^
ReferenceError: ns is not defined

ns.PromiseAlias is an alias, doesn't have an implementation. Is this correct? thanks.

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptFixedA PR has been merged for this issue

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions