TypeScript 2.0 borrows from Rust and Swift

TypeScript 2.0 borrows from Rust and Swift

With the TypeScript 2.0 release candidate, Microsoft's typed superset of JavaScript mimics a tagged unions type capability featured in languages like Rust and Swift. Through this feature, developers can cut down on writing boilerplate code.

Daniel Rosenwasser, Microsoft program manager for TypeScript, used an example in which two types, "Circle" and "Square," have a union type, "Shape." In TypeScript 1.8, writing a function to get the area of Shape required a type assertions for each type, whereas TypeScript 2.0 understands how to discriminate based on the "kind" field.

"Tagged unions are an exciting new feature that brings functionality from languages like F#, Swift, Rust, and others to JavaScript while embracing the way that people write JavaScript today," Rosenwasser said. Tagged unions make it easier to get type safety using JavaScript patterns developer would write today. "For example, libraries like Redux will often use this pattern when processing actions," he noted.

The release candidate also features more literal types. "We wanted to give some more love to types other than just 'string'," Rosenwasser said. "In 2.0, each unique 'boolean,' 'number,' and 'enum' member will have its own type." The new version adds globs, for writing out wild cards for paths when working with tsconfig.json file capability, reducing tedium for developers.

The release candidate is downloadable for use with Visual Studio 2015 and can be accessed via NuGet or NPM, using NPM install -g typescript@rc.

IDG Insider

PREVIOUS ARTICLE

«Fujitsu now making DRAM killer with 1,000x performance boost

NEXT ARTICLE

Windows 10 Mobile review: Small fixes show this plucky phone OS won’t give up»
author_image
IDG Connect

IDG Connect tackles the tech stories that matter to you

Add Your Comment

Recommended for You

kathryn-cave

Blockchain For Dummies: What you really need to know

Kathryn Cave looks at the big trends in global tech

martin-veitch-thumbnail

What we know and don’t know about digital transformation

Martin Veitch's inside track on today’s tech trends

silhouette

Four hot IT growth areas to guarantee a big salary bump

IDG Connect tackles the tech stories that matter to you

Most Recent Comments

Our Case Studies

IDG Connect delivers full creative solutions to meet all your demand generatlon needs. These cover the full scope of options, from customized content and lead delivery through to fully integrated campaigns.

images

Our Marketing Research

Our in-house analyst and editorial team create a range of insights for the global marketing community. These look at IT buying preferences, the latest soclal media trends and other zeitgeist topics.

images

Poll

Should companies have Bitcoins on hand in preparation for a Ransomware attack?