[英]How do I compile Typescript to with nodejs 4?
既然nodejs4支持类和箭头函数,我怎么告诉typescript不要填充它?
now that nodejs4 support classes and arrow functions, how do I tell typescript not to polyfill it
既然nodejs4支持类和箭头函数,我怎么告诉typescript不要填充它
You might think you can use target es6
, but don't . 您可能认为可以使用
target es6
, 但不能 。 Eg the following in TypeScript : 例如TypeScript中的以下内容:
function test(bar = 123){
}
Compiles to JavaScript with target es6: 使用目标es6编译为JavaScript:
function test(bar = 123) {
}
But default parameters aren't supported by node yet ( reference ) 但是节点尚不支持默认参数 ( 参考 )
Till the compatibility table of Node exceeds that of TypeScript ... be very careful! 直到Node的兼容性表超过 TypeScript的兼容性表...非常小心! or just
target es5
. 或者只是
target es5
。
Assuming you're using TypeScript now for node, you are likely specifying that your target output is ES5. 假设您现在将TypeScript用于节点,则可能指定目标输出为ES5。 Which means that it will polyfill/transpile ES6/7 features into the paradigm of ES5 in order to run in today's browsers and previous versions of node.
这意味着它将ES6 / 7功能填充/转换为ES5的范例,以便在今天的浏览器和以前版本的节点中运行。
In order to use those features of ES6 today in node v4 you would just need to change your build process to output ES6 via the target option. 为了在节点v4中使用ES6的这些功能,您只需要通过目标选项更改构建过程以输出ES6。
Note: this is true if you are using command line arguments or a tsconfig.json 注意:如果您使用命令行参数或tsconfig.json,则为true
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.