TypeScript

TypeScript is an open-source front end scripting language. It is a strict syntactical superset of JavaScript which adds optional static typing. It is specially designed for development of large applications and compiles to JavaScript.

Features:

  • TypeScript supports other JS libraries
  • It is possible to use this Typescript on any environment that JavaScript runs on
  • It supports definition files that can contain type information of existing JavaScript libraries, such as C/C++ header files
  • It is portable across browsers, devices, and operating systems
  • It can run on any environment that JavaScript runs on

Benefits of TypeScript:

TypeScript is a superset of JavaScript that gives you advantages like:

  • Optional static typing (the key here is optional)
  • Type Inference, which gives some of the benefits of types, without actually using them
  • Access to ES6 and ES7 features, before they become supported by major browsers
  • The ability to compile down to a version of JavaScript that runs on all browsers
  • Great tooling support with IntelliSense

Because of these awesome features and the huge advantages it gives to you as a developer, Ionic apps are written in TypeScript, instead of ES6.

Optional Static Typing:

Most likely, the first thing that comes to mind with TypeScript is the optional static type system that it provides. Types can be added to variables, functions, properties, etc. This will help the compiler and show warnings about any potential errors in code, before an app is ever run. Types also help when using libraries and frameworks, as they let developers know exactly what type of data APIs expect. The key thing to remember about the type system is that it is optional. TypeScript does not force developers to add types they don’t want to add. However, as an app gets larger and more complex, types can provide some great advantages.

Intellisense:

One of the biggest advantages of TypeScript is its code completion and IntelliSense. Intellisense provides active hints as code is added. Since Ionic itself is written in TypeScript as well, editors can present all the methods available and what they expect as arguments. All the best IDE’s available today have support for code completion, including VScode, Atom, WebStorm, Sublime text, and even command line editors, such as Vim/Neovim!

TypeScript’s many benefits provide a much better app development experience. Because of this, Ionic is going “all in” on TypeScript, rather than providing ES6 starters.

JavaScript is far from the best-designed language and has a number of features and quirks that make it difficult to build large-scale applications:

  • It’s easy to define a variable in a global namespace in JavaScript
  • The equality operator (“==”) type coercion rules are confusing and error-prone
  • “This” keyword can refer to a different object when used inside a function depending upon the way that function was invoked

These are just a few of the examples of standard JavaScript behaviors that can be confusing and error-ridden code.