Microsoft TypeScript 2.0 Language — Ready for Prime Time in IT?

Last Update: Sep 04, 2024 | Published: Sep 23, 2016

SHARE ARTICLE

Microsoft TypeScript 2.0
Anders Heljsberg regrets a C# omission (2009)

Microsoft updates TypeScript language to 2.0. It’s an open-source superset of JavaScript, but said to be easier to use, more productive, create more reliable code, and compile down to standard JavaScript.

Version 2.0 adds features such as non-nullable types and expanded control flow analysis. Plus tagged unions, the never type, this types for functions, and of course glob support. Got all that?

Anyway, it’s gaining huge momentum among developers. In today’s IT Newspro, we resist the temptation to say developersdevelopersdevelopers.

Your humble newswatcher curated these news nuggets for your entertainment. Not to mention: A Heljsberg chalk-talk


What’s the story? Peter Bright shines a light on TypeScript:

TypeScript, the JavaScript-based languagedevised to make developing large Web applications easier, reached its version 2.0 milestone.With TypeScript, Microsoft is aiming to introduce some of the same checking and validation thatlanguages such as C#, Java, and C++ performwhile still remaining compatible withJavaScript.

TypeScript seems to be winning over a good number of JavaScript developers. Google has given the project its backing by adopting TypeScript for its Angular 2 framework.Microsoft has been running it as a community-driven open source project, too. [It’s] one of the success stories of Redmond’s embrace of open source.


You hear that Mister Tim Anderson? That is the sound of inevitability: [You’re fired -Ed.]

TypeScript first appeared in October 2012backed by Microsoft’s Anders Heljsberg – the inventor of C# andBorland’s Delphi.The TypeScript compiler emits standard JavaScript code; no special runtime is required.

[It] is hosted on GitHub.com, where it is the 15th most popular languagewith 250 per cent growth year on year.The most notable feature in TypeScript 2.0 is non-nullable types.The compiler will checkfor variables set to null, and forvariables that are used before [being] assigned.


Let’s go to the horse’s mouth, shall we? Microsoft’s Daniel Rosenwasser is excited to announce the announcement—TypeScript 2.0 is now available:

We’re excited to announce the final release of TypeScript 2.0!TypeScript is JavaScript that scales.

[It] allows developers to use existing JavaScript code, incorporate popular JavaScript libraries, and call TypeScript code from JavaScript. [It] enables JavaScript developers to use highly-productive development tools and practices like static checking and code refactoring.

With this release, TypeScript delivers close ECMAScript spec alignment, wide support for JavaScript libraries and tools, anda first class editing experience in all major editors. [It’s] an even more productive and scalable JavaScript development experience.


Sounds cool. How do I get it? Arif Bacchus liberates us from self-conscious fear:

To download TypeScript 2.0you must update TypeScript 2.0 for Visual Studio 2015 with Update 3. To grab it with NuGet, start using TypeScript 2.0 in Visual Studio Code. For, Visual Studio “15” Preview usersTypeScript 2.0 will be included in the next Preview release.


And what’s next? Mary Jo Foley knows all about it:

Moving forward, Microsoft plans to focus on enhancing thelanguage service and set of tooling.


Fine, but is there a wider context to this? Paul Krill displays an anachronistic image:

It is part of a roster of JavaScript alternatives, such as CoffeeScript, that areeasier for developers. Key improvementsinclude simplified declaration file acquisition, in which declarations for a library are made easier.

Control flow analyzed types in version 2.0 can produce the most specific type possible.Also, immutable programming has been made easier.In future versions, [they] plan to evolve the type system to allow further expression of JavaScript in a statically typed fashion.


But what’s the big deal with disallowing NULL? shutdown -p now explains:

In [JavaScript] etc., null means lack of value, “absent”. And that is not a bad concept, you run into this sort of thing all the time.

The problem is that the type system is unsound – every reference type is implicitly considered an option type with null. And yet any operation on a reference is permitted even when it wouldn’t be allowed on null – hence, runtime exceptions.

[TypeScript] solves that problem outright. If you have a typed reference, by default, it cannot be null, and any code that’s trying to assign to it something that might be null simply won’t compile. In those places where you actually want to allow null, you can explicitly spell it out in the type, but then you’ll have to do null-checks before you access any member (which effectively changes the type of reference inside the conditional statement to the default never-null type). Again, the compiler enforces all that – so if your entire program was typechecked, there cannot be any runtime null errors.

Effectively, they made null into a true monadic option type, like ‘a option in ML, or Maybe a in Haskell.


Wait, I still don’t quite get it. rasmusbr cuts to the chase:

If you and everyone on your team always writes correct code then it doesn’t matter how you encode non-existent values.The problem is that writing correct code is sometimes hard and often takes a lot of time.


And Finally…

Anders Heljsberg brings us up to speed

Main image credit: D. Bagley (cc:by)

SHARE ARTICLE