Menu

React, etc. Tech Stack

React, Flux, GraphQL, Hack, HHVM...? All of this and more!

TypeScript over JavaScript and Babel?

TypeScript is a language that builds ontop of standard JavaScript. It uses the familiar ECMAScript 6 syntax, but adds features to it. TypeScript is then transformed to plain JavaScript that is interpreted by browsers or other platforms capable of running JavaScript.

The conversion from TypeScript to JavaScript is called transpiling. It's technically compiling from one source code to another. It's a common practise with modern JavaScript and the most common tool for this is currently Babel. Written source for Babel is currently ECMAScript 2015 (ES6) syntax and target language being ES5, the lowest common denominator for popular browsers at this point in in time.

You can use TypeScript in a similar fashion as Babel, just as a JavaScript converter, but as a superset of JavaScript TypeScript has some unique features. In addition to the transpiling architecture in place it has additional tooling and features that are simply not does not have before (if ever) the ECMAScript standard will include these.

In addition to commonly used ES6 features such as classes, modules, The "arrow" syntax for anonymous functions, optional parameters and default parameters TypeScript users get access to advanced features that allow manageability of large codebases. TypeScript originates from Microsoft, a company with decades of experience in creating developer tooling.

TypeScript does not require "all in" strong typing

Programming languages are classified as strongly typed or weakly typed. A strongly typed language requires you to define what type your variables in your code are where as a weakly typed (or loosely typed) language allows developers to omit these definitions completely. In general a strongly typed language is somewhat more laboursome to write, but with types the computer has more information on the intent of the developer. JavaScript is a weakly typed language, but through TypeScript it gets optional strong typing.

With type annotations and compile-time type checking developers get access to advanced debugging features with a minimum overhead. In addition to client implementation projects written in TypeScript, a number of high profile JavaScript frameworks such as Angular 2Aurelia, DojoEmberIonicNativeScript have all embrace TypeScript. This is a testament that for large projects strong typing has holds an advantage.

TypeScript is much advertised for large projects, but it does not over complicate simple projects either. As a weakly typed JavaScript language developers don't care too much about what type of primitives they are using. Unlike Java or other strong typed languages, with TypeScript you don't need to go all in on typing.

When using TypeScript you don't have to define types for everything, but still enjoy the benefits through type inference which automatically sets types per how they were first defined. A variable initially set as an array will result in an error if you try to change it to a string later on.

With the recent momentum behind TypeScript it's safe to say the project is here to stay. As an Open Source project building on ECMAScript standards and a well defined roadmap it is likely a better long term investment than learning a single high level JavaScript library like React.

With TypeScript developers can enjoy the benefits of strong typing without going all in on them.

Written by Jorgé on Saturday July 30, 2016

Permalink -

« Aurelia 1.0 released - Popular WordPress plugin allows authenticated users to execute any PHP on page load »