Skip to content

Async/Await with custom promise when targeting ES6 and CommonJS #5789

@ghost

Description

Seems like tsc uses invalid class name when targeting ES6 and CommonJS, at least with custom promises in async functions.

// Task.ts
export class Task<T> extends Promise<T> {}

// Test.ts
import { Task } from "./Task";
class Test
{
    async Example<T>(): Task<T> {}
}

compiled to

// Task.js
class Task extends Promise {}
exports.Task = Task;

// Test.js
var __awaiter = ...
var Task_1 = require("./Task");
class Test
{
    Example() { return __awaiter(this, void 0, Task, function* () {}); }
}

Instead of return __awaiter(this, void 0, Task, function* () {}); should be return __awaiter(this, void 0, Task_1.Task, function* () {}); since Task is imported as Task_1.Task when using commonjs.

1.8.0-dev.20151125
tsc --target es6 --module commonjs

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptFixedA PR has been merged for this issueHigh Priority

Type

No type
No fields configured for issues without a type.

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions