BT

Facilitating the Spread of Knowledge and Innovation in Professional Software Development

Write for InfoQ

Topics

Choose your language

InfoQ Homepage News TypeScript 2.5 Released, Adds Language Level Refactoring

TypeScript 2.5 Released, Adds Language Level Refactoring

Leia em Português

This item in japanese

Bookmarks

In version 2.5 of TypeScript, Microsoft has focused on developer productivity and broadened the scope of what it can do by offering features typically found in code editors.

Developers accustomed to typed languages such as C# have enjoyed tooling that can easily perform common refactorings. Now, TypeScript has the ability to use its knowledge of the code to perform perform Extract Function and Extract Method refactorings. But TypeScript is a language service, not an editor, so the addition of this feature to the language service means that all editors will be able to hook into the service to provide this refactoring. Daniel Rosenwasser, program manager for TypeScript, says the team is focused on the developer experience, not just the language:

TypeScript as a language is developed with the editing experience in mind, and so our team works on both the compiler/type-checker as well as the language service that powers editors like VS Code in mind. It's not just VS and VS Code. The changes are available to any editor that consumes our language service, and so I think these editing features will be useful to know about as a TypeScript user.

These refactorings will show up in VS Code and Visual Studio soon.

Microsoft also boosted the "quick fix" arsenal by catching accidental usages of JSDoc type declarations and incorrect type referencing. The quick fix language service API was first made available in TypeScript 2.1 and includes corrections such as spelling, missing imports, missing this, and unused declarations. More fixes are already on the roadmap.

This release is light on language features, but one of the only notable ones is called optional catch variables. This ability is useful when you need to catch an error, but you don't care about the actual contents of the error. This feature is actually a part of an ECMAScript proposal. The following code, which does not include a declaration of the caught error, is now valid:

try {
    const result = someMethodThatWillThrowAnException();
}
catch {
    contents = createDefaultContents();
}

As always, the latest version of TypeScript can be installed with npm install -g typescript or on NuGet.

Rate this Article

Adoption
Style

BT