gilamran
gilamran

Reputation: 7294

How do I compile Typescript to with nodejs 4?

now that nodejs4 support classes and arrow functions, how do I tell typescript not to polyfill it?

Upvotes: 3

Views: 604

Answers (2)

basarat
basarat

Reputation: 275927

now that nodejs4 support classes and arrow functions, how do I tell typescript not to polyfill it

You might think you can use target es6, but don't. E.g. the following in TypeScript :

function test(bar = 123){

}

Compiles to JavaScript with target es6:

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! or just target es5.

Upvotes: 4

Brocco
Brocco

Reputation: 64893

Assuming you're using TypeScript now for node, you are likely specifying that your target output is 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.

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.

Note: this is true if you are using command line arguments or a tsconfig.json

Upvotes: 1

Related Questions