What is TypeScript?
‘TypeScript is a typed superset of JavaScript that compiles to plain JavaScript.‘ While that all sounds very fancy, it pretty much boils down to JavaScript, but with lots of added juicy bits.
The Juicy Bits
Recently, new versions of JavaScript became available, but are not currently supported by all major browsers. TypeScript allows us to leverage all the new benefits by allowing developers to write client-side logic in a similar way to server-side logic.
Classes
Classes in TypeScript are very similar to those in C#. They are tidy and provide clean layouts. Take the following greeting example;
A straightforward object, but this can be easily extended and allows interfaces to be added. Allowing us, as developers, to leverage well-established design patterns such as S.O.L.I.D principles more simply. After compiling, we are presented with a standard JavaScript Object:
This might seem silly to create a class, then compile it to JavaScript, there are a host of benefits to utilising this approach. We can create better code in a shorter amount of time while maintaining consistent standards.
Optional Static Typing
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.
Other Benefits of TypeScript
- Easily compile to JavaScript to run on all browsers
- Built-in compiler
- Easy integration with modern frameworks
- Can be used server and client side
Do I need it?
It all depends, are you wanting to leverage the latest and greatest features of JavaScript written in a way that follows sensible design patterns? Then the answer is yes!
Do you want to write scalable JavaScript that can run well anywhere? Then most certainly you should be using TypeScript!
TypeScript offers a whole host of scalable benefits, so no matter the size of a web application, TypeScript will be more than able to handle the task. For me, it is a no-brainer, TypeScript should be adopted and I can guarantee that we will start to see more web applications created with this outstanding language.
Further reading can be found on the TypeScript documentation. For any further advice on TypeScript, contact our IT experts.
If you are in need of some assistance with web development, please don’t hesitate to contact our web design team who will be happy to help!