Skip to content

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

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

Closed
ryasmi opened this issue Dec 24, 2015 · 12 comments
Closed

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

ryasmi opened this issue Dec 24, 2015 · 12 comments
Labels
Duplicate An existing issue was already created External Relates to another program, environment, or user action which we cannot control. Question An issue which isn't directly actionable in code

Comments

@ryasmi
Copy link

ryasmi commented Dec 24, 2015

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.

@DanielRosenwasser
Copy link
Member

I'm not seeing this behavior. Can you try out the current nightly by running npm install -g typescript@next and letting us know if that fixes it?

@DanielRosenwasser DanielRosenwasser added the Needs More Info The issue still hasn't been fully clarified label Dec 24, 2015
@ryasmi
Copy link
Author

ryasmi commented Dec 25, 2015

I have new errors on the nightly build, will look into this after Christmas @DanielRosenwasser, merry Christmas! 😄

@ryasmi
Copy link
Author

ryasmi commented Dec 25, 2015

@DanielRosenwasser the compiler seems to be ignoring my tsconfig.json file.

@DanielRosenwasser
Copy link
Member

Can you share a minimal repro? Or share the project itself?

@ryasmi
Copy link
Author

ryasmi commented Dec 25, 2015

Nothing has changed in my project, on the nightly build you can use my tsconfig with a typescript file using a promise, run the command I shared above and you'll hit error TS2304: Cannot find name 'Promise' and if you use a async function you'll get error TS1311: Async functions are only available when targeting ECMAScript 6 and higher. I didn't get those errors previously.

@ryasmi
Copy link
Author

ryasmi commented Dec 25, 2015

Ok fixed those errors by just stuffing all of my options into a command (#5980 can't come soon enough).

find src -name "*.ts" -type f >ts-files.txt; tsc @ts-files.txt --module commonjs -t es6 --noImplicitAny --removeComments --preserveConstEnums --sourceMap --jsx react --outDir es6; rm -f ts-files.txt;

Now I get module errors like...

error TS2307: Cannot find module ...

Judging by some of the type errors I'm getting in addition to this, it's also ignoring my typings directory 😢 Sublime Text isn't showing any of these errors with the TypeScript package.

@ryasmi
Copy link
Author

ryasmi commented Dec 27, 2015

Everything compiles fine, but when I run tsc with the tsconfig below, I get TS2307 and TS2304 errors like it's ignoring the "node_modules" and "typings" directories. For the record, my project has three directories, "node_modules", "typings", and "src" (which contains my ts files). I'm running tsc from the root.

{
  "compilerOptions": {
    "module": "commonjs",
    "target": "es6",
    "noImplicitAny": true,
    "removeComments": true,
    "preserveConstEnums": true,
    "sourceMap": true,
    "jsx": "react",
    "outDir": "es6",
    "rootDir": "src"
  },
  "exclude": [
    "node_modules",
    "typings"
  ]
}
error TS2307: Cannot find module 'firebase'.
error TS2304: Cannot find name 'process'.

@DanielRosenwasser
Copy link
Member

Without knowing more about your actual project, it's difficult for me to diagnose the issue. Can you share the repo at all?

@ryasmi
Copy link
Author

ryasmi commented Dec 28, 2015

Yeah sorry, I understand that, I can't share the repo though unfortunately. My original issue is resolved in the nightly so I'm happy to close this issue, however I think there are some issues in the nightly around node_modules and typings. If I manage to figure out exactly why I'll create a new issue. Thanks for trying to help @DanielRosenwasser.

@ryasmi
Copy link
Author

ryasmi commented Dec 29, 2015

For the record I've isolated my TS2307 issue in https://github.com/ryansmith94/TS2307-Issue @DanielRosenwasser

I have import * as React from 'react'; which is giving me the error Cannot find module 'react' in "./src/app.ts". However, react is installed in "./node_modules". My target and module compiler options are set to "es6". The error is given by the TypeScript Sublime Text 3 package (v0.11.1) and gulp-typescript (v2.10.0) with TypeScript (v1.7.5) installed globally via npm.

Quoted from a message I put on Gitter.

@ryasmi
Copy link
Author

ryasmi commented Dec 29, 2015

That issue has been resolved on Gitter.

@ryasmi ryasmi closed this as completed Dec 29, 2015
@DanielRosenwasser
Copy link
Member

In the interest of helping people who run into any similar issue, here is the link to the resolution in the Gitter chat on December 29, 2015 5:29 PM.

@DanielRosenwasser DanielRosenwasser added Duplicate An existing issue was already created Question An issue which isn't directly actionable in code External Relates to another program, environment, or user action which we cannot control. and removed Needs More Info The issue still hasn't been fully clarified labels Dec 30, 2015
@microsoft microsoft locked and limited conversation to collaborators Jun 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Duplicate An existing issue was already created External Relates to another program, environment, or user action which we cannot control. Question An issue which isn't directly actionable in code
Projects
None yet
Development

No branches or pull requests

2 participants