|Written by Alex Denham|
|Friday, 23 January 2015|
Microsoft has announced TypeScript 1.4, with union types, type guards, and more.
Writing about the new version on the TypeScript blog, Microsoft’s Jonathan Turner says that the team has
The addition of support for union types is designed to provide a way to handle Java functions that take a number of possible argument types.
Up to now, TypeScript has supported this by using function overloads, but this capability has been generalized so you are now allowed to specify that that a value is one of a number of different types using a union type. Once you have a value of a union type, you can use typeof and instanceof checks to use the value in a type-safe way.
Type aliases are another improvement; you can now define an alias for a type using the type keyword. The alias is exactly the same as the original type, but can be used to make your code easier to read.
A more restricted form of enums has also been added. The blog post says that “for heavy uses of enums, it’s helpful to have an even more restricted form that we know is safe to always inline. This helps with performance, code size, and with working with cases where the enum aliases themselves may not be exported. Starting with TypeScript 1.4, you’ll be able to make const enums.”
One of the main goals for the upcoming TypeScript 2.0 release is to fully support the ECMAScript 6 standard, and TypeScript 1.4 gets closer to this, with the addition of a new ES6 output mode, support for let and const, and support for ES6 template strings.
The ES6 output mode is added to the ‘--target' command line option. This now allows you to choose between ES3, ES5 and ES6 output modes.
Template strings are another area of improvement. These are special strings that can freely mix in expressions, allowing a lighter syntax when pieces of a string depend on associated values. With the 1.4 release, TypeScript now supports ES6 template strings and can also compile them down to ES3/ES5 expressions.
To be informed about new articles on I Programmer, install the I Programmer Toolbar, subscribe to the RSS feed, follow us on, Twitter, Facebook, Google+ or Linkedin, or sign up for our weekly newsletter.
or email your comment to: firstname.lastname@example.org
|Last Updated ( Friday, 23 January 2015 )|