Microsoft: TypeScript isn't a JavaScript killer

It's not about the language, it's about the tools

The Power of One Brief: Top reasons to choose HP BladeSystem

Build 2012 Microsoft may have a poor track record for web standards compliance, but if the capacity crowd at Microsoft Technical Fellow Anders Hejlsberg's Build conference session on TypeScript was any indication, Redmond's JavaScript alternative has struck a nerve with coders who have grown frustrated with the web's de facto applications language.

"We have teams and customers writing, with regularity, 100,000-line JavaScript applications, in a language you could argue was designed for 100-line applications," Hejlsberg said, to appreciative nods from the audience.

During his Thursday morning talk on Microsoft's Redmond campus, Hejlsberg argued that building such large JavaScript applications successfully is simply too difficult. The bigger a project's code base grows, the more likely it is to contain subtle and confusing bugs, which can lead to data corruption, security vulnerabilities, or worse.

But Hejlsberg said TypeScript, the alternative web language he created with a team of Microsoft developers, isn't meant to replace JavaScript, but to build on it.

TypeScript isn't the first tool aimed at solving the problem of application-scale JavaScript coding. Google, in particular, has been experimenting with its own JavaScript alternatives for several years, first with the Google Web Toolkit and later with the Dart language. But Hejlsberg couldn't resist taking a jab at the Chocolate Factory's efforts for straying too far afield.

"Unlike certain other languages that target JavaScript," Hejlsberg said, "we actually start with JavaScript, meaning that any valid piece of JavaScript code is valid TypeScript. You just cut and paste the code."

Rather than simply remaking JavaScript in its own image, Hejlsberg explained, Microsoft had a different goal when it created TypeScript. Specifically, it wanted to make it possible to create world-class developer tools that would make building large web applications easier, without breaking compatibility with existing browsers and standards.

That should come as no surprise, given that Microsoft is arguably the leading commercial developer tools vendor. Even some Redmond haters grudgingly admit that Visual Studio is one of the best IDEs in the business.

But building an IDE like Visual Studio that works with JavaScript is impossible, Hejlsberg said, because of JavaScript's dynamic type system. Without the ability to know which data types a function is expecting as its parameters or what data types it's expected to return, there's no way to implement the kind of code hinting and completion to which Visual Studio users are accustomed, let alone to analyze the code for hidden bugs.

TypeScript = JavaScript++

To fix this, TypeScript starts with ordinary JavaScript syntax and adds additional features. For example, it adds a static type system that allows developers to specify which objects should be strings, which should be numbers, and so on.

This static typing in TypeScript is completely optional. Developers can add type annotation to all of their objects and variables or just a few. In fact, Hejlsberg said, specifying types for just a few identifiers in a program is often enough to allow the TypeScript parser to infer the rest automatically.

The key, he said, is that TypeScript doesn't go out of its way to create data types that weren't available in JavaScript already. "TypeScript's type system is basically just a formalization of JavaScript's type system," Hejlsberg explained. "We're not trying to make something new here; we're just trying to formalize what already exists."

Because all valid JavaScript code is also valid TypeScript code, Hejlsberg said, it's even possible to write TypeScript declaration files that specify type information for existing JavaScript libraries, granting them all the IDE-friendliness of libraries written in pure TypeScript without ever altering the code of the libraries themselves.

He added that the TypeScript community has been hard at work creating such definition files, and that the current TypeScript distribution already includes ones for many of the more popular JavaScript libraries and frameworks, including jQuery and Node.js.

In fact, Hejlsberg said, the TypeScript distribution doesn't have a standard library of its own. Although libraries can certainly be written in the language, its core resources are the same as JavaScript's.

In addition to static typing, TypeScript also introduces a new object orientation model, replacing JavaScript's prototype-based model with a model based on classes and interfaces that will be more familiar to developers accustomed to languages like C++ and Java. Additionally, TypeScript adds the concept of modules, making it easier to break large code bases into components whose code can be isolated from one another.

But even these differences aren't such a huge break from JavaScript, Hejlsberg noted, because the way they have been implemented is essentially the same as the work being done on classes and interfaces for ECMAScript 6, the open standard that is likely to become the next version of JavaScript.

"Before we declare [TypeScript] 'done,' if ECMAScript 6 moves to a different model, then we will likely follow, because we're still just a preview of what the final product will be," Hejlsberg said.

What's next for TypeScript?

But similarities between TypeScript and ECMAScript 6 don't mean they are the same language, nor will they ever be. Specifically, Hejlsberg said, there are no plans to include static typing in ECMAScript, which is the feature that really sets TypeScript apart and that enables the kind of sophisticated tooling that Microsoft envisions.

And while some of that tooling is already available in the TypeScript plugin for Visual Studio 2012, he said, Microsoft has still more planned. In particular, limited support for debugging TypeScript code is available now, but "thorough" support will come with future releases.

The TypeScript language will undergo further changes, too. One feature Hejlsberg said he would like to add to the language was generics, which he said would be inspired by C# generics but would work differently.

The mention of C# spurred another question that had been much on the minds of this year's Build conference attendees, however: If Hejlsberg, the father of C#, is spending all of his time on TypeScript these days, what does it mean for the leading language of .Net? Does C# have a future?

But Hejlsberg brushed off the idea that he was abandoning his earlier brainchild, insisting that there were enough hours in the day for him to work on both TypeScript and C#. "C# is still going strong," he said, "it's just that right now there's a big need for JavaScript to improve."

Judging by the large and animated crowd at Hejlsberg's Build session – who had to be ushered out of the room to make way for a new session before all of their questions could be answered – a great many developers agree. ®

Securing Web Applications Made Simple and Scalable

More from The Register

next story
Apple fanbois SCREAM as update BRICKS their Macbook Airs
Ragegasm spills over as firmware upgrade kills machines
HIDDEN packet sniffer spy tech in MILLIONS of iPhones, iPads – expert
Don't panic though – Apple's backdoor is not wide open to all, guru tells us
Mozilla fixes CRITICAL security holes in Firefox, urges v31 upgrade
Misc memory hazards 'could be exploited' - and guess what, one's a Javascript vuln
NO MORE ALL CAPS and other pleasures of Visual Studio 14
Unpicking a packed preview that breaks down ASP.NET
Captain Kirk sets phaser to SLAUGHTER after trying new Facebook app
William Shatner less-than-impressed by Zuck's celebrity-only app
Cheer up, Nokia fans. It can start making mobes again in 18 months
The real winner of the Nokia sale is *drumroll* ... Nokia
EU dons gloves, pokes Google's deals with Android mobe makers
El Reg cops a squint at investigatory letters
Chrome browser has been DRAINING PC batteries for YEARS
Google is only now fixing ancient, energy-sapping bug
prev story


Designing a Defense for Mobile Applications
Learn about the various considerations for defending mobile applications - from the application architecture itself to the myriad testing technologies.
How modern custom applications can spur business growth
Learn how to create, deploy and manage custom applications without consuming or expanding the need for scarce, expensive IT resources.
Reducing security risks from open source software
Follow a few strategies and your organization can gain the full benefits of open source and the cloud without compromising the security of your applications.
Boost IT visibility and business value
How building a great service catalog relieves pressure points and demonstrates the value of IT service management.
Consolidation: the foundation for IT and business transformation
In this whitepaper learn how effective consolidation of IT and business resources can enable multiple, meaningful business benefits.