Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TypeScript: What's the "right" `target` for node 11?

TypeScript's has a target configuration with many values, like esnext, es2015, es6 etc. (very confusing)

NodeJs current version (11.11.0) supports many of the new features of JavaScript. Is it ok to target esnext on TypeScript? will it work?

If not, what's the right target to use when targeting nodeJs 11.11.0

Edit:

Thanks to @Seblor we know that esnext is very dynamic and TC39 can add features as they see fit. It represents the next version of JavaScript that is being worked on (Regarding agreeing on features)

The refined question should be: According to the current version of NodeJs (11.11.0) and the current version of TypeScript (3.3) can we use esnext as the target?

like image 656
gilamran Avatar asked Mar 11 '19 09:03

gilamran


People also ask

Is TypeScript good for Nodejs?

TypeScript is well-established in the Node. js world and used by many companies, open-source projects, tools and frameworks. Some of the notable examples of open-source projects using TypeScript are: NestJS - robust and fully-featured framework that makes creating scalable and well-architected systems easy and pleasant.

Is TypeScript better than Nodejs?

"Npm", "Javascript" and "Great libraries" are the key factors why developers consider Node. js; whereas "More intuitive and type safe javascript", "Type safe" and "JavaScript superset" are the primary reasons why TypeScript is favored.

When should we select node js?

Node. js is primarily used for non-blocking, event-driven servers, due to its single-threaded nature. It's used for traditional web sites and back-end API services, but was designed with real-time, push-based architectures in mind.


2 Answers

Looking at node.green, ES2018 support seems to be full in Node 11.11.0, so you should be able to set ES2018 as target with no trouble.

You can push your luck by using ES2019 or even ESNext since the support looks good enough. However, I do not know if typescript will use non-yet-implemented features if you use ESNext as target (like the private properties).

Personally I would stick with ES2018, as I see no need to push for ESNext.

like image 153
Seblor Avatar answered Sep 19 '22 18:09

Seblor


Based on Node-Target Mapping on the TypeScript wiki "es2018" is the right mapping for Node 10, "es2019" is the right mapping for Node 12. It seems that non-LTS versions of Node aren't documented, but given this information I feel like "es2018" is the safest target.

like image 33
Walter Rumsby Avatar answered Sep 18 '22 18:09

Walter Rumsby