TypeScript 2.5
Optionalcatch clause variables
Thanks to work done by@tinganho, TypeScript 2.5 implements a new ECMAScript feature that allows users to omit the variable incatch clauses.For example, when usingJSON.parse you may need to wrap calls to the function with atry/catch, but you may not end up using theSyntaxError that gets thrown when input is erroneous.
tsletinput ="...";try {JSON.parse(input);}catch {// ^ Notice that our `catch` clause doesn't declare a variable.console.log("Invalid JSON given\n\n" +input);}
Type assertion/cast syntax incheckJs/@ts-check mode
TypeScript 2.5 introduces the ability toassert the type of expressions when using plain JavaScript in your projects.The syntax is an/** @type {...} */ annotation comment followed by a parenthesized expression whose type needs to be re-evaluated.For example:
tsvarx =/**@type{SomeType} */AnyParenthesizedExpression;
Deduplicated and redirected packages
When importing using theNode 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 apackage.json containing the samename andversion 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 containprivate 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 thepreserveSymlinks flag, which parallels the behavior ofthe--preserve-symlinks flag in Node.js.This flag also exhibits the opposite behavior to Webpack’sresolve.symlinks option (i.e. setting TypeScript’spreserveSymlinks totrue parallels setting Webpack’sresolve.symlinks tofalse, 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 tothe documentation on the Node.js website.
The TypeScript docs are an open source project. Help us improve these pagesby sending a Pull Request ❤
Last updated: Dec 16, 2025