Microsoft’s TypeScript gets fitted with better compilation

29.01.2016
Microsoft has gone to a beta release with TypeScript 1.8, the latest upgrade to the company's typed superset of JavaScript, featuring improvements in compilation and the usage of third-party libraries.

TypeScript compiles to JavaScript. In version 1.8, available for the Visual Studio 2015 IDE, the compiler can consume JavaScript files alongside TypeScript files. In a blog post, Microsoft's Bowden Kelly said the conversion process from JavaScript to TypeScript at times could be "menacing" for large projects, possibly yielding a lot of compilation errors.

"However, by allowing JavaScript files into the TypeScript compiler, it is now possible to convert one file at a time while still compiling your entire project all together," Kelly said. "This allows developers to be in full control of where and how they want to carry out the conversion, making converting sizable projects much more manageable."

Microsoft is using the recently released ChakraCore compiler with TypeScript when possible. "We found ChakraCore achieved significantly reduced compilation times, outperforming the previous version of Chakra that we were using by 5-20 percent and Node by 10-50 percent," said Kelly.

Using third-party JavaScript libraries is easier in version 1.8; developers are able to simply include these libraries in compilation and they will follow emitted JavaScript. Previously, developers needed a third-party bundler such as webpack or browserify.

A TypeScript NuGet package is provided to improve ease of acquisition. The TypeScript compiler and MSBuild task will be distributed as a NuGet package. "In addition to these official releases, we will also be hosting the nightly build of TypeScript on MyGet," which is a hosted NuGet server on Azure, Kelly said. "These are not supported builds, but feel free to check them out and let us know what you think."

Control flow analysis in the upgrade helps catch common errors, Microsoft said in its GitHub page on TypeScript. In version 1.8 it is also now possible for a type parameter constraint to reference type parameters from the same type parameter list. This capability has been referred to as F-bounded polymorphism and previously was considered an error in TypeScript.

TypeScript 1.8 expands support for JSX, an embeddable XML-like syntax, by enabling custom JSX factories. "While React has paved the way, JSX syntax is not only tied to React. As such, a JSX factory should be able to be overridden from the default React factory. Using the new compiler flag --reactNamespace <factory_name> in combination with --jsx react, TSX authors can now control the emit of the factory name," Kelly said. Also, TypeScript picks up syntax highlighting for JSX from Visual Studio 2015. "With the TypeScript 1.8 update in Visual Studio, JSX tags will now get classified and colorized, improving the readability of the code."

TypeScript was introduced by Anders Hejlsberg, chief architect of Visual C#, in 2012. It has emerged as a JavaScript alternative, similar to CoffeeScript and Google's Dart, but it's seen as having a tough hill to climb to compete with JavaScript, for cultural rather than technical reasons.

(www.infoworld.com)

Paul Krill