{"componentChunkName":"component---src-templates-handbook-tsx","path":"/docs/handbook/release-notes/typescript-2-5.html","result":{"data":{"markdownRemark":{"id":"2f52c589-667d-5abe-9102-25dd84c81197","excerpt":"Optional catch clause variables Thanks to work done by @tinganho, TypeScript 2.5 implements a new ECMAScript feature that allows users to omit the variable in…","html":"<h2 id=\"optional-catch-clause-variables\"><a href=\"#optional-catch-clause-variables\" aria-label=\"optional catch clause variables permalink\" class=\"anchor\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Optional <code>catch</code> clause variables</h2>\n<p>Thanks to work done by <a href=\"https://github.com/tinganho\">@tinganho</a>, TypeScript 2.5 implements a new ECMAScript feature that allows users to omit the variable in <code>catch</code> clauses.\nFor example, when using <code>JSON.parse</code> you may need to wrap calls to the function with a <code>try</code>/<code>catch</code>, but you may not end up using the <code>SyntaxError</code> that gets thrown when input is erroneous.</p>\n<pre class=\"shiki\"><div class=\"language-id\">ts</div><div class='code-container'><code><span style=\"color: #0000FF\">let</span><span style=\"color: #000000\"> input = </span><span style=\"color: #A31515\">\"...\"</span><span style=\"color: #000000\">;</span>\n<span style=\"color: #0000FF\">try</span><span style=\"color: #000000\"> {</span>\n<span style=\"color: #000000\">    JSON.parse(input);</span>\n<span style=\"color: #000000\">}</span>\n<span style=\"color: #0000FF\">catch</span><span style=\"color: #000000\"> {</span>\n<span style=\"color: #000000\">    </span><span style=\"color: #008000\">// ^ Notice that our `catch` clause doesn't declare a variable.</span>\n<span style=\"color: #000000\">    console.log(</span><span style=\"color: #A31515\">\"Invalid JSON given\\n\\n\"</span><span style=\"color: #000000\"> + input)</span>\n<span style=\"color: #000000\">}</span></code></div></pre>\n<h2 id=\"type-assertioncast-syntax-in-checkjsts-check-mode\"><a href=\"#type-assertioncast-syntax-in-checkjsts-check-mode\" aria-label=\"type assertioncast syntax in checkjsts check mode permalink\" class=\"anchor\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Type assertion/cast syntax in <code>checkJs</code>/<code>@ts-check</code> mode</h2>\n<p>TypeScript 2.5 introduces the ability to <a href=\"https://github.com/Microsoft/TypeScript/issues/5158\">assert the type of expressions when using plain JavaScript in your projects</a>.\nThe syntax is an <code>/** @type {...} */</code> annotation comment followed by a parenthesized expression whose type needs to be re-evaluated.\nFor example:</p>\n<pre class=\"shiki\"><div class=\"language-id\">ts</div><div class='code-container'><code><span style=\"color: #0000FF\">var</span><span style=\"color: #000000\"> x = </span><span style=\"color: #008000\">/** </span><span style=\"color: #0000FF\">@type</span><span style=\"color: #008000\"> {SomeType} */</span><span style=\"color: #000000\"> (AnyParenthesizedExpression);</span></code></div></pre>\n<h2 id=\"deduplicated-and-redirected-packages\"><a href=\"#deduplicated-and-redirected-packages\" aria-label=\"deduplicated and redirected packages permalink\" class=\"anchor\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Deduplicated and redirected packages</h2>\n<p>When importing using the <code>Node</code> module resolution strategy in TypeScript 2.5, the compiler will now check whether files originate from “identical” packages.\nIf a file originates from a package with a <code>package.json</code> containing the same <code>name</code> and <code>version</code> fields as a previously encountered package, then TypeScript will redirect itself to the top-most package.\nThis helps resolve problems where two packages might contain identical declarations of classes, but which contain <code>private</code> members that cause them to be structurally incompatible.</p>\n<p>As a nice bonus, this can also reduce the memory and runtime footprint of the compiler and language service by avoiding loading <code>.d.ts</code> files from duplicate packages.</p>\n<h2 id=\"the---preservesymlinks-compiler-flag\"><a href=\"#the---preservesymlinks-compiler-flag\" aria-label=\"the   preservesymlinks compiler flag permalink\" class=\"anchor\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>The <code>--preserveSymlinks</code> compiler flag</h2>\n<p>TypeScript 2.5 brings the <code>preserveSymlinks</code> flag, which parallels the behavior of <a href=\"https://nodejs.org/api/cli.html#cli_preserve_symlinks\">the <code>--preserve-symlinks</code> flag in Node.js</a>.\nThis flag also exhibits the opposite behavior to Webpack’s <code>resolve.symlinks</code> option (i.e. setting TypeScript’s <code>preserveSymlinks</code> to <code>true</code> parallels setting Webpack’s <code>resolve.symlinks</code> to <code>false</code>, and vice-versa).</p>\n<p>In this mode, references to modules and packages (e.g. <code>import</code>s and <code>/// &#x3C;reference type=\"...\" /></code> 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.\nFor a more concrete example, we’ll defer to <a href=\"https://nodejs.org/api/cli.html#cli_preserve_symlinks\">the documentation on the Node.js website</a>.</p>","headings":[{"value":"Optional catch clause variables","depth":2},{"value":"Type assertion/cast syntax in checkJs/@ts-check mode","depth":2},{"value":"Deduplicated and redirected packages","depth":2},{"value":"The --preserveSymlinks compiler flag","depth":2}],"frontmatter":{"permalink":"/docs/handbook/release-notes/typescript-2-5.html","title":"TypeScript 2.5"}}},"pageContext":{"slug":"/docs/handbook/release-notes/typescript-2-5.html","isOldHandbook":true}}}