15 Jul 2016

Why RealEyes Switched to TypeScript.

Within the past few months RealEyes has switched from using JavaScript as its main development language to TypeScript. We have successfully launched a large production application developed entirely using TypeScript and have found the change to be helpful and has increased productivity.

Why TypeScript?

Readability

The most attractive benefit to using TypeScript in my opinions is readability. The ability to create a more readable code base that explicitly states class declarations, and property types is something that was missing from JavaScript.

Take a simple namespace with a class definition developed in both JavaScript and TypeScript:

Screen Shot 2016-06-27 at 12.10.33 PM

JavaScript namespace and class declaration.

Screen Shot 2016-06-27 at 12.11.01 PM

TypeScript namespace and class declaration.

Notice how with TypeScript we are able to explicitly state our namespace and class, unlike JavaScript where that is inferred and only a seasoned developer would understand what is actually occurring. With TypeScript we are also explicitly able to provide variable types and return types within the code without having to spend time creating additional documentation with tables to define everything for other developers to use.

Code Hinting

With TypeScript your IDE or Text Editor can be setup in such a way to allow for easy hinting to display property types, return types, and comments. This increases productivity so that a fellow developer doesn’t have to find the documentation for the library or class that they are using or have to look at any source code to determine what is required and what the expected output is. When working within teams where many developers are working on multiple services this ability to quickly show each other all the types is invaluable.

Take the following screenshots:

Screen Shot 2016-06-27 at 11.19.09 AM

TypeScript: available class found within ‘test’ module

Screen Shot 2016-06-27 at 11.17.45 AM

Class definition hint

Screen Shot 2016-06-27 at 11.21.04 AM

Class constructor properties hint

Screen Shot 2016-06-27 at 11.22.32 AM

Available properties and methods on SomeClass

With TypeScript and a plugin with your favorite IDE or Text Editor such as WebStorm, VSCode, Sublime Text, Atom, etc; we can show available class or properties found within an external module, view class constructor properties and return types, and view class properties and methods. You can also add any documentation about the properties or methods by adding simple comments within the module.

This ability to show module classes and class properties and methods also extends outside of your teams code base. Using a popular npm module Typings you can download definition files for your favorite libraries such as JQuery and then have access to that libraries type definitions.

Screen Shot 2016-06-27 at 11.48.47 AM

Sample of available properties and methods on JQuery library

Valid JavaScript is Valid TypeScript

Since TypeScript is an encapsulation of JavaScript (ES7, ES6, and ES5) not only do we get to use the new methods provided with ES6 and ES7, all valid JavaScript is valid TypeScript. This means that even though we enforced strict typing and class structure within our development environments through linters (tslint) and the tsconfig; sometimes when a developer who is still learning TypeScript needed to quickly lay down some comfortable JS logic to solve a problem. It was still able to transpile and work without them being blocked by a learning curve. This then allowed the team to learn the TypeScript way at a more leisurely pace instead of being thrown into the deep end without a life vest.

Popularity

TypeScript has quickly become a popular language within the web development industry. With Angular 2‘s adoption of the language, many other developers and companies are quickly moving to TypeScript. Meaning that this language will be receiving a lot of support within the community, and more developers will be learning and practicing this language. Additionally with the familiar layout of other object oriented languages such as Java, or C#, it may start attracting more developers who found JavaScript unattractive and confusing.

Share this
26 Aug 2015

Using JMeter to Load Test Live HLS Concurrency of Wowza Streaming Engine

When I was tasked with determine the max users that an m4.xlarge AWS instance running WowzaStreamingEngine delivering HLS content could reliably handle; I found out quickly I had a fairly difficult task ahead of me. Luckily I found a few blog posts that pointed me in the right direction and provided the base JMeter test plan to work with.

read more
Share this
09 Jul 2015
16 Jan 2015

© 2017 RealEyes Media, LLC. All rights reserved.