I'm trying to get this to work in VSCode, but I can't seem to find a solution anywhere.
I just want to use Generator in Typescript with VSCode, but i found that the nodejs can't support keyword "import" .
If use "ES5" as target in tsconfig.json, typescript can't support Generator in VSCode.
Here is demo:
// typescript app.ts
import * as http from "http";
http.createServer((request, response) => {
response.writeHead(200, {"Content-Type": "text/html"});
response.write("Hello World!");
response.end();
}).listen(8000);
And then get this
/// <reference path="typings/tsd.d.ts" />
import * as http from "http";
http.createServer((request, response) => {
response.writeHead(200, { "Content-Type": "text/html" });
response.write("Hello World!");
response.end();
}).listen(8000);
//# sourceMappingURL=app.js.map
run by node --harmony app.js or node --harmony_modules app.js all get:
g:\Temp\TypeScriptTest>node --harmony app.js
g:\Temp\TypeScriptTest\app.js:2
import * as http from "http";
^^^^^^
SyntaxError: Unexpected reserved word
at exports.runInThisContext (vm.js:53:16)
at Module._compile (module.js:413:25)
at Object.Module._extensions..js (module.js:452:10)
at Module.load (module.js:355:32)
at Function.Module._load (module.js:310:12)
at Function.Module.runMain (module.js:475:10)
at startup (node.js:117:18)
at node.js:951:3
Or use
import http = require("http"); // ES5 require module style
VSCode warning
Import assignment cannot be used when targeting ECMAScript 6 or higher. Consider using 'import * as ns from "mod"', 'import {a} from "mod"' or 'import d from "mod"' instead.
Has some way to typescript compile *.ts file use ES6 style import module and I can use ES6 features such as Generator in Typescript?
var ns = require("mod")after tsc compile the *.ts.