Type Script 2.0 makes cabbage on Java Scripts dreaded ‘undefined’

Microsoft Type Script

Credits: Version2.dk

Javascript is one of the most used programming thanks to the support of all major browsers, but it is also a language with restrictions that have led to a growing stream of different frameworks in recent years has expanded Javascript with features sought after by developers.Microsoft Type Script goes in a slightly different direction and offer a programming language that provides many of the features known from the large application-programming language, but translated into Javascript.

As the name might suggest, it is one of the useful features of Type Script possibility for type-resistance, so when compiler his Type Script, do the compiler a type check, so you all get a type of real output in JavaScript, even Javascript in itself not type fast .

Version 2.0 of Attraction Script was released recently , and Type Script is now so established that several of the major frameworks for Javascript is about to switch to it, and the example was Angular 2 written in Type Script.

Among the novelties in Type Script 2.0 is that null and undefined are now actual types, and it makes it easier to take into account that you sometimes risk getting either one or the other return.

“Undefined and null is probably number one source for bugs in Javascript. Now is undefined a type in Type 2.0. It is especially useful when you have some data from APIs, and they send a undefined back. It tends to give a crash if you do not handle it in his code, “says lead front-end developer Dennis Haulund Nielsen from development house Nodes to Version2.

To utilize this feature in Type Script 2.0 must, however, beat the strict null checks to. The Microsoft recommends that you do, but it may cause problems with existing code, and therefore it is so far optional.

New syntax and object-oriented programming

One of the special things about Type Script is that ordinary Javascript code can be inserted as part of a program written in Type Script. Type Script is a ‘superset’ of Javascript. ‘Del’ means that all Javascript – including the features that are coming in future standards – is a proper subset of Type Script.

But it gets a little more complicated than that, for Type Script uses a slightly different syntax than Javascript.

“I had never coded anything other than Javascript. There is a learning curve, but it’s worth it for large projects. If you have a small project, then it is probably not worth it to put all the tools up to Type Script, “says Dennis Haulund Nielsen.

Type Script defines example return types of methods such as the syntax of Swift, but a little different than languages ​​like C # and Java, but like the two languages, then type Script also thought to support object-oriented programming.

“It is often used as an argument against Type Script that they have taken an overall architectural choices. But we’re still object-oriented in this house, “says Dennis Haulund Nielsen.

Compatible with all browsers

Javascript is already used for many types of applications, but it takes time to introduce new features in the language. It’s one of the reasons why there are so many frameworks for Javascript.

Type Script translator for Javascript standard ES5, but there is also a ES6 and ES2016 + underway.They are supported yet by all browsers, while you have to return to Internet Explorer 8 to run into trouble with ES5.

ES5 is also a subset of the more recent standards, and they are also subsets of script type. This means that code written in Type Script should be compatible with future versions of Javascript.

As these newer versions of Javascript is also included in Type Script, it also provides the opportunity to tag them as part of a Type Script application that so right now will translate to the older ES5.

Help for major projects

For developers provide Type Script opportunity to use some more advanced tools than is possible only with Javascript and various frameworks. For example it is easier for multiple developers to work together.

“With a good IDE you get autocomplete and Intellisense. It’s easier to work on a team when colleagues can quickly see such arguments to a library. It flies more along, when codes, “explains Dennis Haulund Nielsen.

At Nodes developers are in the process of transferring the core components that are being used in several projects to Type Script inter alia, increasing the quality assurance of the code.

“We recycle the modules in many projects, so it makes sense that they will be as flawless as possible.Therefore it makes sense to put the time in to port them, “says Dennis Haulund Nielsen.

Another new feature of Type Script 2.0 is also helpful to the larger projects, namely the ability to make properties read-only. It can help to prevent that two developers working in their own part of the code gets introduced code that will overwrite each other’s objects.