How to get generator support in typescript without setting a target on ES6?

There is a situation here. I am using nodejs with the --harmony flag to get generator support. Then I try to switch my project to TypeScript and get the problem: in the "target":"ES6" it translates the import commands as they are (instead of require ).

And node with the --harmony flag --harmony not support this:

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

The overflow option "module":"commonjs not allowed with "target":"ES6" .

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

+3
source share
3 answers

These settings worked for me:

tsconfig.json

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

And now the problem has disappeared!

+4
source

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

I'm afraid you will need a workaround until TypeScript 1.7 is released. Perhaps Polyfill for the ES6 or SystemJS module loader ?

0
source

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

  • Transpile TS to ES6
  • Move es6-js to es5-js with Babel
0
source

All Articles