Skip to content
This repository has been archived by the owner on Mar 25, 2021. It is now read-only.

Function generator: error in yield statement #706

Closed
zdychacek opened this issue Oct 2, 2015 · 7 comments
Closed

Function generator: error in yield statement #706

zdychacek opened this issue Oct 2, 2015 · 7 comments

Comments

@zdychacek
Copy link

Hi,

I am getting an error in yield statement 'Error: expected an assignment or function call' message in following code:

function *g (): Iterable<number> {
    for (let i: number = 0; i < 100; i++) {
        yield i;
    }
}

Is there really any error in my code?

Thanks for your reply,

O.

@adidahiya
Copy link
Contributor

This looks like an error reported by the compiler rather than TSLint... can you post your full stack trace or console output?

@jkillian
Copy link
Contributor

jkillian commented Oct 2, 2015

A problem on the TSLint side might be that we target ES5 instead of ES6. I think generators only work in ES6.

@zdychacek
Copy link
Author

When I run tslint main.ts I get following main.ts[3, 3]: expected an assignment or function call, so I think this issue has something to do with TSLint.

I am targetting ES6.

Here is my tsconfig.json:

{
  "compilerOptions": {
    "module": "commonjs",
    "noImplicitAny": true,
    "target": "es6",
    "experimentalDecorators": true
  }
}

Hope this information helps somehow.

Thanks,

O.

@jkillian
Copy link
Contributor

jkillian commented Oct 2, 2015

@zdychacek Sorry, I didn't mean that you need to be targeting ES6; I meant that TSLint ought to have an option that makes it target ES6 when analyzing your code. I don't know if that's the issue for sure though. Definitely a bug either way, thanks for reporting it!

@jkillian
Copy link
Contributor

jkillian commented Oct 2, 2015

Seems like we can handle this better even when internally targeting ES5, see the above PR. Should be in a release sometime soon

@zdychacek
Copy link
Author

Great, thank you!

O.

@adidahiya
Copy link
Contributor

the fix will be released in v2.5.2. until then, I think you can avoid the issue with /* tslint:disable */ flags?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants