You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm using TS to write Node application. Since the newer Node version(4.x) now supports most ES6 features, I set tsconfig.json to be like this:
{
"compilerOptions": {
"target": "ES6"
}
}
However, after compiled, these js files can not run in Node because import is still a reserved word and not supported by Node yet.
After I alter tsconfig.json to:
Cannot compile modules into 'commonjs', 'amd', 'system' or 'umd' when targeting 'ES6' or higher.
So I got stuck here: If I want to use es6 features such as generator,for of, I have to set compile target to es6, but if I do so, both ts and js files would have to be import and export in es6 way, which is not currently supported by Node.
For now, I'm using Babel to convert es6 files to es5. However, it seems too heavy, babel does a lot of polyfill work and the final generated codes are hard for human to read.
So I'm asking if there is some better way of doing this: benefit from writing ts in es6 syntax while directly compile code to js that Node.js can run.
The text was updated successfully, but these errors were encountered:
Hereis the scenario:
I'm using TS to write Node application. Since the newer Node version(
4.x
) now supports most ES6 features, I settsconfig.json
to be like this:However, after compiled, these js files can not run in Node because
import
is still a reserved word and not supported by Node yet.After I alter
tsconfig.json
to:then I get a compile error:
So I got stuck here: If I want to use es6 features such as
generator
,for of
, I have to set compile target to es6, but if I do so, both ts and js files would have to be import and export in es6 way, which is not currently supported by Node.For now, I'm using
Babel
to convert es6 files to es5. However, it seems too heavy, babel does a lot of polyfill work and the final generated codes are hard for human to read.So I'm asking if there is some better way of doing this: benefit from writing ts in es6 syntax while directly compile code to js that Node.js can run.
The text was updated successfully, but these errors were encountered: