Skip to content

async/await compiles to yield outside of a generator #6242

Closed
@ryasmi

Description

@ryasmi

The following TypeScript with async/await...

public async get(from: number, to: number): Promise<Array<M>> {
  let models: Array<M> = await this.persistant_repo.get(from, to);

produces the following JavaScript with a yield outside of a generator...

ModelsRepoDecorator.prototype.get = function (from, to) {
  var _this = this;
  var models = yield this.persistant_repo.get(from, to);

I'm not certain, but I don't think yield should work outside of a generator. I'm running tsc src/**/*.ts --outDir dist --sourceMap and my tsconfig looks like this...

{
  "compilerOptions": {
    "module": "commonjs",
    "target": "ES6",
    "noImplicitAny": true,
    "removeComments": true,
    "preserveConstEnums": true,
    "sourceMap": true,
    "jsx": "react"
  }
}

I think this may be a duplicate of #4135, but I'm not sure how the solution there can be applied here.

Metadata

Metadata

Assignees

No one assigned

    Labels

    DuplicateAn existing issue was already createdExternalRelates to another program, environment, or user action which we cannot control.QuestionAn issue which isn't directly actionable in code

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions