TypeScript 2.0 is almost out, and today we’re happy to show just how close we are with our release candidate! If you haven’t used TypeScript yet, check out the intro tutorial on our website to get started.
To start using the RC now, you can download TypeScript 2.0 RC for Visual Studio 2015 (which requires VS Update 3), grab it through NuGet, or use npm:
npm install -g typescript@rc
Visual Studio Code users can follow the steps here to use the RC.
This RC gives an idea of what the full version of 2.0 will look like, and we’re looking for broader feedback to stabilize and make 2.0 a solid release. Overall, the RC should be stable enough for general use, and we don’t expect any major new features to be added past this point.
On the other hand, lots of stuff has been added since 2.0 beta was released, so here’s a few features that you might not have heard about since then.
Tagged Unions
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. This feature is also called discriminated unions, disjoint unions, or algebraic data types. But what’s in the feature is much more interesting than what’s in the name.
Let’s say you have two types: Circle and Square. You then have a union type of the two named Shape.
interface Circle {
kind: "circle";
radius: number;
}
interface Square {
kind: "square";
sideLength: number;
}
type Shape = Circle | Square;
Notice that both Circle and Square have a field named kind which has a string literal type. That means the kind field on a Circle will always contain the string "circle". Each type has a common field, but has been tagged with a unique value.
In TypeScript 1.8, writing a function to get the area of a Shape required a type assertions for each type in Shape.
function getArea(shape: Shape) {
switch (shape.kind) {
case "circle":
// Convert from 'Shape' to 'Circle'
let c = shape as Circle;
return Math.PI * c.radius ** 2;
case "square":
// Convert from 'Shape' to 'Square'
let sq = shape as Square;
return sq.sideLength ** 2;
}
}
Notice we made up intermediate variables for shape just to keep this a little cleaner.
In 2.0, that isn’t necessary. The language understands how to discriminate based on the kind field, so you can cut down on the boilerplate.
function getArea(shape: Shape) {
switch (shape.kind) {
case "circle":
// 'shape' is a 'Circle' here.
return Math.PI * shape.radius ** 2;
case "square":
// 'shape' is a 'Square' here.
return shape.sideLength ** 2;
}
}
This is totally valid, and TypeScript can use control flow analysis to figure out the type at each branch. In fact, you can use --noImplicitReturns and the upcoming --strictNullChecks feature to make sure these checks are exhaustive.
Tagged unions make it way easier to get type safety using JavaScript patterns you’d write today. For example, libraries like Redux will often use this pattern when processing actions.
More Literal Types
String literal types are a feature we showed off back in 1.8, and were tremendously useful. Like you saw above, we were able to leverage them to bring you tagged unions.
We wanted to give some more love to types other than just string. In 2.0, each unique boolean, number, and enum member will have its own type!
type Digit = 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9;
let nums: Digit[] = [1, 2, 4, 8];
// Error! '16' isn't a 'Digit'!
nums.push(16);
Using tagged unions, we can express some things a little more naturally.
interface Success<T> {
success: true;
value: T;
}
interface Failure {
success: false;
reason: string;
}
type Result<T> = Success<T> | Failure;
The Result<T> type here represents something that can potentially fail. If it succeeds, it has a value, and if it fails, it contains a reason for failure. The value field can only be used when success is true.
declare function tryGetNumUsers(): Result<number>;
let result = tryGetNumUsers();
if (result.success === true) {
// 'result' has type 'Success<number>'
console.log(`Server reported ${result.value} users`);
}
else {
// 'result' has type 'Failure'
console.error("Error fetching number of users!", result.reason);
}
You may’ve noticed that enum members get their own type too!
enum ActionType { Append, Erase }
interface AppendAction {
type: ActionType.Append;
text: string;
}
interface EraseAction {
type: ActionType.Erase;
numChars: number;
}
function updateText(currentText: string, action: AppendAction | EraseAction) {
if (action.type === ActionType.Append) {
// 'action' has type 'AppendAction'
return currentText + action.text;
}
else {
// 'action' has type 'EraseAction'
return currentText.slice(0, -action.numChars);
}
}
Globs, Includes, and Excludes
When we first introduced the tsconfig.json file, you told us that manually listing files was a pain. TypeScript 1.6 introduced the exclude field to alleviate this; however, the consensus has been that this was just not enough. It’s a pain to write out every single file path, and you can run into issues when you forget to exclude new files.
TypeScript 2.0 finally adds support for globs. Globs allow us to write out wildcards for paths, making them as granular as you need without being tedious to write.
You can use them in the new include field as well as the existing exclude field. As an example, let’s take a look at this tsconfig.json that compiles all our code except for our tests:
{
"include": [
"./src/**/*.ts"
],
"exclude": [
"./src/tests/**"
]
}
TypeScript’s globs support the following wildcards:
*for 0 or more non-separator characters (such as/or\).?to match exactly one non-separator character.**/for any number of subdirectories
Next Steps
Like we mentioned, TypeScript 2.0 is not far off, but using the RC along with 2.0’s new features will play a huge part in that release for the broader community.
Feel free to reach out to us about any issues through GitHub. We would love to hear any and all feedback as you try things out. Enjoy!

Nice work, team!!! I can’t wait to play with this!
Still the bleeding-edge guy I see. Bring it on! ๐
Congratulations for all efforts put in this release! ๐
Can’t tell you how much we love TypeScript on my team. Thanks for everything!!
Can’t wait to get a 2.0 release, thanks for hard work!
That’s it? Wow. Typical msft.
I see 94 issues fixed since the beta. Here: https://github.com/Microsoft/TypeScript/issues?q=is%3Aissue+milestone%3A%22TypeScript+2.0.2%22+label%3A%22fixed%22+
So your disappointed because you did not get more free software for your … um… money?….
Can’t help but think that comes off a bit spoiled/entitled. Maybe not intended that way, but that is how it came across to me.
your != you’re
I think it’s more like he’s disappointed Microsoft did not get more for *their* money.
Those in-house developers working on TS must cost at least 1 million a year.
Where have we seen this before? With every version of Windows.
Also with the Hololens. Terrible aesthetic design IMO.
On which they surely spent an ungodly sum.
It’s all downhill from here. At least they have a few hundred million to burn.
So do you actually USE TypeScript? Or are you just an Apple/Linux fan girl looking for forums to rail on Microsoft? Given how quickly you switched over from TypeScript to ragging on Windows and Hololens, I’d guess the latter.
Truth.
@Laura Truth.
@Jamie Seems to me you are the fan boy. She didn’t say anything about Apple or Linux.
WTF?
What does it have to do with anything?
These are the notable changes between 2.0 Beta and 2.0 RC. Logically some minor things. But TS 2.0 contains a lot of new impressive features since version 1.8. See: https://github.com/Microsoft/TypeScript/wiki/What's-new-in-TypeScript#typescript-20
Definitely wow ๐
You know, TypeScript IS open source. If you’re not satisfied with their progress, why don’t you fork and contribute? There are some extremely talented people working on this project (it’s principal architect also designed C# and Delphi), so I sincerly doubt anyone has been just sitting on their thumbs.
It would be concerning if there were a lot of new features between the beta and RC.
Typical non-sense, pointless post.
Great!!! TypeScript is beaultifull
Is there support for the new @types style of declaration files in Visual Studio yet?
In your post “The Future of Declaration Files” you said that support for Visual Studio is on the way. But you never followed up to say when support is planed (or was added).
Can you give an update for this? I would like to test it out, but without Visual Studio support there is little point in even trying it out.
Stephen
FYI: I love Typescript. Thanks to the glories of Typescript, I get to treat JavaScript is Bytecode. I very rarely need to read it!
yes @types are supported in VS too, I’ve been using that for a while now.
Congratulations !!! Nice to see, it’s available with vs 2015 .
Kudos to the team who burned midnight oil to reach this milestone.
By now, I’m pretty sure TS 2.0 will release before Angular 2.0…
Apparently not…
Well done folks!
Well done! We published a Chinese version here: http://www.cnblogs.com/onecodeonescript/p/5829687.html
Thanks Daniel to you and the team for such a great product. TypeScript all the things!
Really great work – thanks a lot!
TypeScript rocks!
Two thumbs way up for globs. I’m up to a couple hundred files.
Will TS 2.0 support VS 2013? Have you drop VS 2013 support on TS 2.0? Do Angular 2 require TS 2.0? Now we are still using VS 2013/TS 1.8.6 to develop Angular 2 RC5 app.
Angular2 Ahead Of Time compiler requires Typescript 2.0.2
Why 2.0? Is it going to break compatibility with 1.x?
https://github.com/Microsoft/TypeScript/wiki/Breaking-Changes
Our IT counsel will not allow any sizable new system to use TS over plain JavaScript for the reasons that ECMA script 6 will be supported by major browsers in less than 1 year, and with ECMA 6 out TS will be much less important. The Silverlight zombie state contributed.
Can keep the TypeScript then and just pass them on the generated Javascript.
So what will they do when work starts on ECMAscript 7 etc.? They will wait for some more years?
btw, Google’s Angular team chose TypeScript for some reasons, see presentation they had done at a recent Microsoft event. Also this one: https://techcrunch.com/2015/03/05/microsoft-and-google-collaborate-on-typescript-hell-has-not-frozen-over-yet/
It seems that your IT Counsel needs some IT counsel.
–R
Love that comment ๐
@Ken, I would suggest that the transpilation of new ECMAScript features to older versions of ECMAScript is a (relatively) secondary goal of Typescript. I think a more primary goal is to catch more errors at write- or compile-time, and not wait for such errors to be discovered at runtime. This is accomplished by Typescript’s type system, static flow analysis, null reference checking, and other features; all of which will probably never be a part of ECMAScript.
Good luck with that attitude. ES6 will be much further behind TS.
What is written (not exactly implemented around) in ES6 is lacking much behind TS already. Not mentioning ES7.
Sidenote: Transpiling in babel is currently damn slow.
Those “Major Browsers” are gonna be still less than 75% of the world in more than 2 years… IMHO
As far as I see it – and have wide experiences with both – there is no comparison possible with Silverlight technology. TS is open-source for instance. That just makes it safe to assume that even after Microsoft drops mic on TS… code will stay.
My predictions for the future are:
1. multi-target compilation and UA-inspection gonna be widely used for the scripts in coming years. You can’t just drop support for 30% of customers. We had previously IE(insert different name depending on team) dedicated web developers sticking to just that… never again.
2. WebAssembly will make slow progress but steady high impact.
After installing this for Visual Studio, I no longer get Intellisense in TypeScript. Anybody else having the same issue?
Same here. No Intellisense. WHelpppppppppppppppppppp !!!
This link: http://download.microsoft.com/download/6/D/8/6D8381B0-03C1-4BD2-AE65-30FF0A4C62DA/TS2.0.2-TS-release20-nightly-20160828.1/TypeScript_Dev14Full.exe taken from the top blog post says Release Candidate in the Hyperlink text, but when I run that installer it says BETA !?!?!?
ah quality control costs…
Hi, sometimes I get a 500 server message when I browse this webpage. Just a heads up, best wishes