If you’re not familiar with TypeScript, it’s a typed superset of JavaScript. More simply put, it’s just JavaScript with optional static types. Static types can make it easier to maintain your code by catching bugs early on, making it easier to navigate your projects, giving accurate code completion, and providing handy fixes for when you do make mistakes. By making types optional, you can get the flexibility of plain JavaScript when you need it, all while TypeScript also gives you the option to tighten things up to bring you more type safety. You can learn more about TypeScript on our website.
To start using TypeScript, you can grab it through NuGet or use the following command with npm:
npm install -g typescript
Visual Studio 2015 users (who have Update 3) can install TypeScript 2.5 from here, and Visual Studio 2017 users using version 15.2 or later will be able to get TypeScript by simply installing it from here. Visual Studio 2017 users should be sure to read up on how you can configure your project to target specific versions of TypeScript.
While TypeScript 2.5 will be available for other editors soon, in the meantime you can configure Visual Studio Code and Sublime Text to use a newer version. Other editors may have different approaches to getting TypeScript 2.5 running.
Let’s look at what TypeScript 2.5 brings!
The Extract Function and Extract Method refactorings
Our team is always in search of ways to bring more powerful tools to the TypeScript and JavaScript world. That’s why with TypeScript 2.5 we’ve invested a lot into implementing extract method and extract function: two new refactorings that make complex rewrites trivial.
If you’re using Visual Studio Code, this refactoring will be available in the upcoming release (though you can try it now by using VS Code Insiders releases).
This feature is still fairly new so we expect that there will still be room for improvement, but we’re excited to hear your feedback so we can polish things out.
New quick fixes
We’ve also added a few quick fixes for when TypeScript can guess a little bit at what you meant to write.
One new quick fix will get triggered when you try to use JSDoc-style types in TypeScript. If you’re in the habit of writing types like these, you might be surprised to find out that they’re not valid in TypeScript, but TypeScript is happy to push us in the right direction.

We’ve also added a quick fix for when you try to reference the type of a property off of another type incorrectly. For example, for the following code
interface Foo {
bar: number;
}
We might want to declare a variable named xyz whose type is tied to to the type of bar. The correct way to write this would be using an indexed access type:
// Get the type of the property named 'bar' off of 'Foo'.
var xyz: Foo["bar"]
but we might accidentally write var xyz: Foo.bar. TypeScript now can now suggest the correct one in many cases.
![A quick fix that corrects `Foo.bar` to `Foo['bar']`.](https://msdnshared.blob.core.windows.net/media/2017/08/propReference.gif)
JSDoc type assertion support in JavaScript files
In TypeScript 2.4, we introduced the ability to get type-checking in JavaScript files so that users can more easily migrate to TypeScript, and have an easier experience with certain more lightweight projects. Taking advantage of this is as simple as adding a // @ts-check at the top of your .js file, or turning on the checkJs flag in yout tsconfig.json‘s compilerOptions.
One thing that it lacked was the ability to “cast” or “assert” the type of an expression. This is important for situations where you know a little more than the type-checker and need to tell it so. To come up with a trivial example, let’s take the following JavaScript code:
// @ts-check
var foo = Math.random() ? "hello" : 100;
foo.toUpperCase();
// ~~~~~~~~~~~
// Error! Property 'toUpperCase' does not exist on type 'string | number'.
TypeScript correctly indicates that we might be calling a method that doesn’t exist on numbers. If we wanted to get around this so we can easily get our runtime error, we could write a JSDoc type assertion:
// Works!
var bar = /** @type {string} */ (foo);
bar.toUpperCase();
The syntax is /** @type {YOUR_TYPE_HERE} */ (someParenthesizedExpression).
Keep in mind that if you’ve enabled JavaScript checking on a file, invalid type assertions will still get caught:
var clearlyNumber = /** @type {string} */ (100);
// ~~~~~~~~~~~~~~
// Error! Type 'number' cannot be converted to type 'string'.
Optional catch clauses
Thanks to work by Tingan Ho, TypeScript 2.5 brings a new ECMAScript-bound feature for making catch clauses optional. Much of the time, you’ll find yourself writing a try/catch but not really caring about the thrown error. For example:
let contents;
try {
contents = fs.readFileSync(".config_file").toString('utf8');
}
catch (unusedError) {
// File might not exist, just fall back to some defaults.
contents = createDefaultContents();
}
Notice that unusedError is never referenced in the above example. Barring philosophical issues about whether it’s appropriate to ignore the error, we can make our code a little cleaner by taking advantage of the fact that the catch variable is now optional.
let contents;
try {
contents = fs.readFileSync(".config_file").toString('utf8');
}
catch {
// File might not exist, just fall back to some defaults.
contents = createDefaultContents();
}
Deduplicated and redirected packages
When importing using the Node module resolution strategy in TypeScript 2.5, the compiler will now check whether files originate from “identical” packages. If a file originates from a package with a package.json containing the same name and version fields as a previously encountered package, then TypeScript will redirect itself to the top-most package. This helps resolve problems where two packages might contain identical declarations of classes, but which contain private members that cause them to be structurally incompatible.
As a nice bonus, this can also reduce the memory and runtime footprint of the compiler and language service by avoiding loading .d.ts files from duplicate packages.
The --preserveSymlinks compiler flag
TypeScript 2.5 brings the preserveSymlinks flag, which parallels the behavior of the --preserve-symlinks flag in Node.js. This flag also exhibits the opposite behavior to Webpack’s resolve.symlinks option (i.e. setting TypeScript’s preserveSymlinks to true parallels setting Webpack’s resolve.symlinks to false, and vice-versa).
In this mode, references to modules and packages (e.g. imports and /// <reference type="..." /> directives) are all resolved relative to the location of the symbolic link file, rather than relative to the path that the symbolic link resolves to. For a more concrete example, we’ll defer to the documentation on the Node.js website.
Enjoy!
We hope our work in TypeScript 2.5 will make you happier and more productive. If it did, let us know on Twitter with the #iHeartTypeScript hashtag.
Out team appreciates any sort of feedback on how we can improve. Feel free to let us know about any issues you run into or helpful ideas you think might make TypeScript even better to use on our GitHub issue tracker.
As for what’s next, we’ve caught most of what’s new on this blog post, but you can always check out our what’s new in TypeScript page on our wiki for some more details, and keep an eye on our Roadmap that highlights our current plans and is frequently updated.
Thanks for reading and happy hacking!

Super.
As always.
— Roberto
Will “Extract Function and Extract Method” work in normal VS 15.3 ?
Hj
We expect extract method and extract function will be available in Visual Studio 2017 version 15.4.
To what extent will Typescript have meaningful enhancements added once the next ECMA script version is included in the major browsers?
How long, which is the end year Typescript have meaningful enhancements added to it? Our team does not want to rewrite one or more of our core applications in Typescript only to have it put into near unsupported/Silverlight status.
ok
Typescript compiles to javascript. You can take those javascript files and stop using Typescript at any time.
Nonsense, no stakeholders paying for a large solution with 100,000+ lines of code would want to pay the extra cost of maintaining generated JavaScript code versus the original TypeScript code.
Silverlight had 3 years of forward development from the version introducing UI controls, e.g., edit boxes, until the announcement of no more new features were to be added to it.
The only way you could come to that conclusion is if you had never looked at Typescript’s generated code.
When you preserve comments and generate in ESNEXT mode, the compiler essentially strips away the type annotations and leaves you with nearly-identical, TC39 Stage-3 compatible ECMAScript code. Perfectly maintainable, perfectly readable.
The single major difference is if you use the “enum” feature, since JavaScript has no equivalent concept. That being said, Union types have been found to be far more useful than enums for 90% of people’s use cases, so you really ought to prefer using those instead.
The first benefit is to make compilation of your solution slower
what the hustle with adding controversial feature like this “optional catch” thing? Is there someone who where writing too much of that style and dying to save keystrokes? Because someone in the community implemented some stuff doesn’t mean you have to slip in in the next release.
Why is it controversial?
Many people (myself included) believe that while it seem harmless in theory, in practice it’ll encourage more reckless exeption handling. When the language has syntax support, it seems more like a normal thing to not check nor log the exception, it shouldn’t.
So, developers shouldn’t have options? If they were going to ignore it, they can do it right now with three additional characters typed…
#iHeartTypeScript
I hope that I could write TypeScript to dev .NET Core app.
Even the beauty of C# cannot save me from TypeScript 🙂
Still waiting for better JSX typing support.
Thanks for the feedback, but what improvements did you have in mind with respect to better type system support for JSX?
Hi, specifically:
https://github.com/Microsoft/TypeScript/issues/14729 (Type JSX elements based on createElement function)
https://github.com/Microsoft/TypeScript/issues/13618 (Suggestion: type checking for JSX children)
This would allow us to use JSX as a custom DSL for various type of configurations/applications. e.g. Permission schemas, DataSource definitions, StateMachines layouts, GUI layout markups etc.
Is this comment not acceptable?
This one: https://github.com/Microsoft/TypeScript/issues/6395
Pure annotation in downlevel emits (https://github.com/Microsoft/TypeScript/issues/13721) is still what was most exciting for me. Think it will at least have a huge effect for those Angular 2+ users who aren’t being very selective of what they’re importing.
Since when are “refactorings” and “quick fixes” part of a language? I always thought of them as IDE features, not language features. Does the TSC compiler actually have a refactoring API that IDE developers can use to provide a refactoring UI without needing to implement the refactoring logic? Or are these merely new features exclusive to the upcoming release of VSCode?
Hey Joel, yes, TypeScript’s language service API is publicly available and built on top of the compiler API itself. The editing experience it provides is utilized by a number of different editors, many which are listed here: https://github.com/Microsoft/TypeScript/wiki/TypeScript-Editor-Support
“the checkJs flag in yout tsconfig.json‘s compilerOptions.”
should be
the checkJs flag in your tsconfig.json‘s compilerOptions.”
I love these new features especially the extract method and extract functions.
Tried to update from TypeScript.2.4.1 to 2.5.2 in VS2015 using nuget and the following error occurs:
Microsoft.TypeScript.targets(247,5): error MSB6006: “tsc.exe” exited with code 1.
Reverting back to TypeScript.2.4.1
We moved to Visual Studio Code and the experience was infinitely better. Hard for me to understand why anyone wants to compile typescript in VS
This is a pretty narrow view point, especially considering it’s not specified who “we” is and what goals “we” has. There is a vast landscape of developers working on solutions that cannot be maintained with VS Code. Just because .Net Core exists doesn’t mean that enterprises the world over have spent money on refactoring the last 15 years’ worth of application development (or would even want to). VS Code is suitable for only a small subset of today’s development. Visual Studio isn’t going anywhere. Regardless of which one you use, there’s one truth that holds for both: TypeScript sure makes it far less nasty to work with JavaScript.
Nice additions!
I am using TypeScript in Visual Studio Code, and It is a fantastic tool. I have developed a MEAN Stack CRUD operations using Angular with the help of VSCode, and their linting is fantastic. You can find my work here. https://appdividend.com/2018/05/27/angular-6-crud-example-mean-stack-tutorial/