Ivan Pesochenko
Ivan Pesochenko

Reputation: 615

How to get support of generators in typescript without setting target to ES6?

Got a situation here. I use nodejs with --harmony flag to get support of generators. Next i'm trying to switch my project to TypeScript and get a problem: in "target":"ES6" mode it transpiles import commands as is (instead of require).

And node with --harmony flag doesn't support that:

import * as fs from 'fs';
^^^^^^
SyntaxError: Unexpected reserved word

Transpiling option "module":"commonjs isn't allowed with "target":"ES6".

Have anyone solved this problem without using any external require/import utilities?

Upvotes: 3

Views: 1613

Answers (3)

Ivan Pesochenko
Ivan Pesochenko

Reputation: 615

Another way to get all i want is a build stack:

  1. Transpile TS to ES6
  2. Transpile es6-js to es5-js with Babel

Upvotes: 0

Ivan Pesochenko
Ivan Pesochenko

Reputation: 615

These settings have worked for me:

tsconfig.json

{
  "compilerOptions": {
    "target":"ES6",
    "moduleResolution": "classic",
  }
}
  • ES6 support for generators
  • No import stuff transpiling due to "moduleResolution": "classic"

And so the problem's gone!

Upvotes: 3

Remo H. Jansen
Remo H. Jansen

Reputation: 24979

As you can see in the TypeScript roadmap (Version 1.7) one of the current issues is "Support --module with --target es6".

I'm afraid your are going to need a temporal solution until TypeScript 1.7 is released. Maybe Polyfill for the ES6 Module Loader or SystemJS?

Upvotes: 1

Related Questions