Professional Web App Development with TypeScript

Professional Web Development with TypeScript

There are thousands of coding “languages” used today. These languages aren’t like what we speak to one another. Rather they are a series of direct commands, abbreviations and ways of arranging text. All software is written in a coding language of some type. Every coding language is unique, designed with a certain operating system, platform, coding style and intended use in mind. Today we are going to take a closer look at one particular language … TypeScript.

While Typescript isn’t exactly brand new – it was introduced in October 2012 – its wide implementation has picked up over the recent years, especially in web applications due to its light-weight deployment and object-oriented nature. Despite this, a lot of developers are still not clear what Typescript is or what advantages it affords them.

TypeScript 101

TypeScript is a strongly typed, object oriented, compiled language. It was designed by Anders Hejlsberg (designer of C#) at Microsoft. TypeScript is both a language and a set of tools. Typescript is an Open Source technology and can run on any browser, any host, and any OS. Typescript is a modern age JavaScript development language (more on that later). It is a statically compiled language to write clear and simple JavaScript code. It can be run on Node js or any browser which supports ECMAScript 3 or newer versions.

TypeScript is made up of the following three components:

  1. Language. It comprises of the syntax, keywords, and type annotations.
  2. The TypeScript Compiler. The TypeScript compiler (tsc) converts the instructions written in TypeScript to its JavaScript equivalent.
  3. The TypeScript Language Service. The "Language Service" exposes an additional layer around the core compiler pipeline that are editor-like applications. The language service supports the common set of a typical editor operations like statement completions, signature help, code formatting and outlining, colorization, etc.

Benefits of TypeScript

Some developers may be hesitant to try a “new” language, which in fact, isn’t so new. TypeScript is gaining in popularity and becoming a real option for organizations that want to develop large coding projects. Notable benefits that TypeScript offers developers include:

  • Static typing. This is a feature that detects bugs as developers write the scripts. This allows developers to write more robust code and maintain it, resulting in better, cleaner code.
  • One of the biggest advantages of TypeScript is its code completion and IntelliSense. Intellisense provides active hints as a code is added.
  • Better choice for large coding projects. TypeScript is an object-oriented language. That means the code is more consistent, clean, simple and reusable. Definitely the option to use for developing large projects.
  • Better for collaboration. Large coding projects have multiple developers, and thus there is a greater chance of errors occurring among them. When errors happen, it makes the handling difficult. TypeScript has safety features that detect errors in coding, which makes for more efficient code and can be debugged easily.
  • Testability. With Dependency Injection, testing becomes easy. You can mock test services with the same interfaces as the real ones. Your code won’t know the difference, and you can perform a full suite of scenarios to get full coverage.
  • Better productivity. Thanks to features like ECMA Script 6 code, dynamic typing and auto-completion, developers are able to boost their productivity.

Why TypeScript over JavaScript?

TypeScript is a typed superset of JavaScript compiled to JavaScript. In other words, TypeScript is JavaScript plus some additional features.

Just in case you need a quick refresher, here’s a brief description of JavaScript and what it does: JavaScript is a programming language used to make web pages dynamic and interactive. You can place JavaScript into an HTML (Hypertext Markup Language) document or make a link or reference to it. JavaScript gives the direction to the browser to do the “dirty work”. If you command an image to be replaced by another one, JavaScript tells the browser to go do it. Because the browser actually does the work, the developer only needs to write some relatively easy lines of code. That’s what makes JavaScript an easy language to start with. JavaScript is now a fundamental building block of the web. Almost every browser supports it, and almost every website uses it.

Did you know JavaScript goes hand-in-hand with SEO? To learn more, check out our blog aboutJavaScript and its impact on SEO here.

TypeScript and JavaScript are linked together because,

  • TypeScript code is converted into plain JavaScript code. TypeScript code is not understandable by the browsers. That’s why if the code is written in TypeScript then it is compiled and converted the code i.e. translate the code into JavaScript.
  • JavaScript is TypeScript. Whatever code is written in JavaScript can be converted to TypeScript by changing the extension from .js to .ts.
  • TypeScript supports JS libraries. With TypeScript, developers can use existing JavaScript code, incorporate popular JavaScript libraries, and can be called from other JavaScript code.

But they do have differences between one another.

  • TypeScript is known as object-oriented programming language whereas JavaScript is a scripting language.
  • TypeScript has a feature known as static typing but JavaScript does not.
  • TypeScript gives support for modules whereas JavaScript does not support modules.
  • TypeScript has Interface but JavaScript does not.
  • TypeScript supports optional parameter function, but JavaScript does not.
  • TypeScript is more commonly used on the client side while JavaScript is used in both client side and server side

So, this is where the question (and a focus of this piece) comes into play – why use TypeScript over JavaScript? The main reasoning is that:

  1. TypeScript is scalable. It was built to handle increasingly complex applications, upscaling towards more big data and large business platforms whereas JavaScript does not.
  2. Typescript is also backed by Microsoft and is integrated with Microsoft’s VS Code, which gives it a definite edge.

Beyond these two primary reasons, other thoughts as to why programmers use TypeScript over JavaScript include:

  • TypeScript always points out the compilation errors at the time of development only. Because of this at the run-time the chance of getting errors are very less whereas JavaScript is an interpreted language.
  • TypeScript has a feature which is strongly-typed or supports static typing. That means static typing allows for checking type correctness at compilation time, which is not available in JavaScript.
  • If an experienced developer is working on relatively small coding projects, then JavaScript is ideal. However, if you have knowledge and an expertise development team, like the team at Code Authority, then Typescript is a preferred option.

The Industry Takes Notice of TypeScript

There is a definite buzz in the industry about TypeScript. In Red Monk’s 2019 Programming Language Listing, TypeScript has moved up from 2018, moving from #17 to #12. According to Red Monk, movement within the top 20 is much more difficult to accomplish so TypeScript’s bump is notable for that reason alone. The findings also note that TypeScript “certainly benefits from its JavaScript proximity, as well as safety features such as the optional static type-checking.”

In another survey, developer marketplace HackerRank asked 71,000 developers around the world about what languages they know today and what they want to learn this year. The results, which were released in its 2019 Developer Skills Report, found that developer interest in TypeScript spiked in the past year, rising from being the fifth most popular language to learn in HackerRank's 2017 developer survey to the fourth most popular language to learn in 2018. They cite that “The language was known by just under a quarter of all developers in 2018 compared with 15 percent last year.”

There’s no question among developers that JavaScript is here to stay and it’s more popular than ever. However, developers who are looking to move to JavaScript from the land of compiled languages now have TypeScript to help them write and manage application-scale JavaScript code.

From TypeScript to JavaScript and every language around and in-between, Code Authority has you covered. Our in-house team of professional web app developers have a keen knowledge of the software solutions that are faster, scalable, and more secure than ever. Contact us today for a consultation on how we can provide a complete digital transformation for your business.