ES6

ES6

Application and Data / Languages & Frameworks / Languages
CEO at Scrayos UG (haftungsbeschränkt)·

For our internal team and collaboration panel we use Nuxt.js (with TypeScript that is transpiled into ES6), Webpack and npm. We enjoy the opinionated nature of Nuxt.js over vanilla Vue.js, as we would end up using all of the components Nuxt.js incorporates anyways and we can adhere to the conventions setup by the Nuxt.js project, which allows us to get better support in case we run into any dead ends. Webpack allows us to create reproducable builds and also debug our application with hot reloads, which greately increased the pace at which we are able to perform and test changes. We also incorporated a lot of testing (ESLint, Chai, Jasmine, Nightwatchjs) into our pipelines and can trigger those jobs through GitLab CI. All packages are fetched through npm, so that we can keep our git repositories slim and are notified of new updates aswell as reported security flaws.

READ MORE
6 upvotes·118K views
Needs advice
on
TypeScriptTypeScript
and
ES6ES6

I consider myself now (after a few years of practice) to be a decent JavaScript/Node.js practitioner. So can someone convince me that I have to learn TypeScript and use it in my everyday life? In other words, why would TypeScript be necessary over some proper ES6 compliant code with strict mode enabled? Any thoughts/opinions are welcome.

EDIT 07/20/2020 : Thank you all for your feedback. I'm definitely going to invest some time in some TypeScript education in the long run. Apart from all the points you made in your responses (static typing, compilation, codebase consistency, etc ...), the fact that Deno may go big (which I hope, the improvements over Node.js could be life changing) and that Visual Studio Code (which I use) is built on top of Electron using TypeScript is what convinces me.

READ MORE
mulekick · GitHub (github.com)
17 upvotes·21.7K views
Replies (8)
Software Engineer at Minna Technologies·
Recommends
TypeScript

I was asking myself this same question a few years ago. I felt that ES6 provided a terse, declarative syntax, that in combination with unit tests was reliable enough. Dynamic typing kept the code looking clean and left most functions generic and reusable for several data types. However, as your code base starts to grow and more and more "ad hoc" data types are introduced. It starts to become very hard to maintain and refactor code because you have to keep long call chains in your head and you sometimes don't know if you can remove a field from an object without introducing a runtime error. In essence, the less strict a programming language is the more you will have to test explicitly all the time. On top of that JavaScript is really good at coercing types in weird ways.

So the main benefit that TypeScript brings is static typing. You make your code more explicit, thereby limiting the number of unintentional behaviors that are possible. The compilers type checker can suddenly take care of testing these extra constraints for you and you start removing this burden from your unit tests. As a matter of fact TypeScript has a pretty advanced type system, a magnitude better than the current Java version (14) or Go-lang. One of these features are union types (aka. coproduct, sum type, etc). This lets you represent your types as "this thing" or "this other thing". Returning a disjoint union can make your code even more explicit and thus further limiting the number of unintentional behaviors. A simple example of this is the head function that returns the first element of a list. Either you get the value or you get undefined if the list is empty. A better approach is to return a Maybe type which is either an instance of Just(<value>) or Nothing. This tells you that the code calling head needs to handle exactly two possible cases. Languages with even stronger type systems like Elm and Haskell can even enforce that your code won't compile unless you handle all the possible cases for any union type. So again the compiler helps you avoid more runtime errors.

So to conclude the benefits of using a language with strong static typing:

  • Compiler helps you avoid runtime errors
  • Substantially reduce number of explicit unit tests
  • Better security and reliability by preventing unintentional behavior
  • Let's you refactor code with confidence
  • Code becomes more self-documenting
READ MORE
22 upvotes·2 comments·12.2K views
Ashwani Agarwal
Ashwani Agarwal
·
July 16th 2020 at 9:12AM

The unintended behaviour of addition (or not knowing the gotchas) on web-browser have always got FE devs scratching their head. I never really got a chance to work on an actual TS project professionally, but having worked with Node.js quite a lot and later moving to Java (mostly for web services), I just didn't want to move back to Node.js. But TS is definitely a game-changer.

·
Reply
Chris Sundberg
Chris Sundberg
·
July 16th 2020 at 9:45AM

Unfortunately there is too much "quick and dirty" rather than "correct, secure and reliable" in our industry.

·
Reply
President & Full Stack Enginee at Narro, LLC·
Recommends
TypeScript

I've been feeling the same way and it was almost too simple for me. First, strongly typed languages are objectively better for catching errors during development instead of during production so a small amount of work upfront pays huge dividends later. But the easy part is how actionable it is.

Find a codebase that you want to convert. For me, it was a server that I wanted to convert to Firebase cloud functions to go serverless. I took my server.js file and copied it as server.ts. I created a simple tsconfig.json file in the root with some standard settings online and then I let the VS Code IntelliSense guide the migration. It was so much easier than I expected and I learned TypeScript as I was converting my codebase.

It was almost too easy and now I have all of the benefits of feature-rich and built-in assistance in my code-editor. Documentation on hover, clear and clean errors. This was only about 2 weeks ago and I am not sure I'd ever go back to Vanilla JS now. It was love at first use with me.

READ MORE
8 upvotes·12.2K views
View all (8)
Senior Fullstack Developer at QUANTUSflow Software GmbH·

Here are our 3 main claims why TypeScript is the way to go.

  • TypeScript is simply JavaScript that scales
  • TypeScript is a superset of JavaScript
  • TypeScript is not a "new" language - It is JavaScript from the future

TypeScript has the following main advantages compared to JavaScript:

  • Typing & Scoping: With static typing, the type of a variable is known at coding time. In dynamic typing the types might be uncertain which could lead to runtime errors. Therefore Strong typing leads to fewer runtime errors. The declaration of variables when it comes to Function Scoping (var) vs. Block Scoping (let) introduced pitfalls lurking in JavaScript. The solution in ES6 - and thus TypeScript - is let. Because variables declared with let follow the rules of block scoping.

  • Collaboration: When large coding projects have many developers there is a chance of messier coding. The number of errors increases which makes the handling difficult. With strong typing the amount of errors decreases and debugging becomes much more easier.

  • Productivity: TypeScript uses the latest ECMA features. Auto-completion features as well as more clear, comprehensible and readable code will boost the productivity of the developer drastically.

READ MORE
16 upvotes·3 comments·36.5K views
Angelo Cicero
Angelo Cicero
·
April 23rd 2020 at 12:23PM

Are you using it with a frontend framework?

·
Reply
Simon Reymann
Simon Reymann
·
April 23rd 2020 at 2:19PM

Yes, we use Vue.js (using Nuxt).

·
Reply
Angelo Cicero
Angelo Cicero
·
April 23rd 2020 at 10:33PM

Cool - I use Vue as well and would love to try Vue 3 out with Typescript.

·
Reply