{"id":2583,"date":"2020-05-12T13:51:04","date_gmt":"2020-05-12T21:51:04","guid":{"rendered":"https:\/\/devblogs.microsoft.com\/typescript\/?p=2583"},"modified":"2020-05-12T23:32:39","modified_gmt":"2020-05-13T07:32:39","slug":"announcing-typescript-3-9","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/typescript\/announcing-typescript-3-9\/","title":{"rendered":"Announcing TypeScript 3.9"},"content":{"rendered":"<p>Today we&#8217;re excited to announce the release of TypeScript 3.9!<\/p>\n<p>If you&#8217;re unfamiliar with TypeScript, it&#8217;s a language that builds on JavaScript by adding syntax for type declarations and annotations. This syntax can be used by the TypeScript compiler to type-check our code, and then output clean readable JavaScript that runs on lots of different runtimes. Static type-checking can tell us about errors in our code before we even run it, or before we even save our files thanks to TypeScript&#8217;s rich editing functionality across editors. But beyond error-checking, TypeScript powers things like completions, quick fixes, and refactorings for both TypeScript <em>and<\/em> JavaScript in some of your favorite editors. In fact, if you already use Visual Studio or Visual Studio Code, you might already be using TypeScript when you write JavaScript code! So if you&#8217;re interested in learning more, <a href=\"https:\/\/www.typescriptlang.org\/\" rel=\"nofollow\">check out our website<\/a>!<\/p>\n<p>But if you&#8217;re already using TypeScript in your project, you can either get it <a href=\"https:\/\/www.nuget.org\/packages\/Microsoft.TypeScript.MSBuild\" rel=\"nofollow\">through NuGet<\/a> or use npm with the following command:<\/p>\n<div class=\"highlight highlight-source-shell\">\n<pre class=\"lang:default decode:true\" style=\"background-color: #f0f0f0;padding: 10px;border-radius: 10px;\">npm install typescript<\/pre>\n<\/div>\n<p>You can also get editor support by<\/p>\n<ul>\n<li><a href=\"https:\/\/marketplace.visualstudio.com\/items?itemName=TypeScriptTeam.TypeScript-39\" rel=\"nofollow\">Downloading for Visual Studio 2019\/2017<\/a><\/li>\n<li><a href=\"http:\/\/code.visualstudio.com\/insiders\" rel=\"nofollow\">Installing the Insiders Version of Visual Studio Code<\/a> or following directions to <a href=\"https:\/\/code.visualstudio.com\/docs\/typescript\/typescript-compiling#_using-newer-typescript-versions\" rel=\"nofollow\">use a newer version of TypeScript<\/a><\/li>\n<li><a href=\"https:\/\/packagecontrol.io\/packages\/TypeScript\" rel=\"nofollow\">Using PackageControl with Sublime Text 3<\/a>.<\/li>\n<\/ul>\n<p>For this release our team been has been focusing on performance, polish, and stability. We&#8217;ve been working on speeding up the compiler and editing experience, getting rid of friction and papercuts, and reducing bugs and crashes. We&#8217;ve also received a number of useful and much-appreciated features and fixes from the external community!<\/p>\n<ul>\n<li><a href=\"#promise-improvements\">Improvements in Inference and <code>Promise.all<\/code><\/a><\/li>\n<li><a href=\"#speed-improvements\">Speed Improvements<\/a><\/li>\n<li><a href=\"#ts-expect-error-comments\"><code>\/\/ @ts-expect-error<\/code> Comments<\/a><\/li>\n<li><a href=\"#uncalled-in-conditionals\">Uncalled Function Checks in Conditional Expressions<\/a><\/li>\n<li><a href=\"#editor-improvements\">Editor Improvements<\/a>\n<ul>\n<li><a href=\"#cjs-auto-imports\">CommonJS Auto-Imports in JavaScript<\/a><\/li>\n<li><a href=\"#preserve-newlines\">Code Actions Preserve Newlines<\/a><\/li>\n<li><a href=\"#missing-returns\">Quick Fixes for Missing Return Expressions<\/a><\/li>\n<li><a href=\"#solution-style-tsconfig\">Support for &#8220;Solution Style&#8221; <code>tsconfig.json<\/code> Files<\/a><\/li>\n<\/ul>\n<\/li>\n<li><a href=\"#breaking-changes\">Breaking Changes<\/a><\/li>\n<\/ul>\n<h2 id=\"promise-improvements\">Improvements in Inference and <code>Promise.all<\/code><\/h2>\n<p>Recent versions of TypeScript (around 3.7) have had updates to the declarations of functions like <code>Promise.all<\/code> and <code>Promise.race<\/code>. Unfortunately, that introduced a few regressions, especially when mixing in values with <code>null<\/code> or <code>undefined<\/code>.<\/p>\n<div class=\"highlight highlight-source-ts\">\n<pre class=\"lang:default decode:true\" style=\"background-color: #f0f0f0;padding: 10px;border-radius: 10px;\"><span style=\"color: #0000ff;\">interface<\/span> <span style=\"color: #267F99;\">Lion<\/span> <span class=\"pl-kos\">{<\/span>\r\n    <span class=\"pl-c1\">roar<\/span><span class=\"pl-kos\">(<\/span><span class=\"pl-kos\">)<\/span>: <span class=\"pl-smi\"><span style=\"color: #0000ff;\">void<\/span><\/span>\r\n<span class=\"pl-kos\">}<\/span>\r\n\r\n<span style=\"color: #0000ff;\">interface<\/span> <span style=\"color: #267F99;\">Seal<\/span> <span class=\"pl-kos\">{<\/span>\r\n    <span class=\"pl-c1\">singKissFromARose<\/span><span class=\"pl-kos\">(<\/span><span class=\"pl-kos\">)<\/span>: <span class=\"pl-smi\"><span style=\"color: #0000ff;\">void<\/span><\/span>\r\n<span class=\"pl-kos\">}<\/span>\r\n\r\n<span style=\"color: #0000ff;\">async<\/span> <span style=\"color: #0000ff;\">function<\/span> <span class=\"pl-en\">visitZoo<\/span><span class=\"pl-kos\">(<\/span><span class=\"pl-s1\">lionExhibit<\/span>: <span style=\"color: #267F99;\">Promise<\/span><span class=\"pl-kos\">&lt;<\/span><span style=\"color: #267F99;\">Lion<\/span><span class=\"pl-kos\">&gt;<\/span><span class=\"pl-kos\">,<\/span> <span class=\"pl-s1\">sealExhibit<\/span>: <span style=\"color: #267F99;\">Promise<\/span><span class=\"pl-kos\">&lt;<\/span><span style=\"color: #267F99;\">Seal<\/span> | <span style=\"color: #0000ff;\">undefined<\/span><span class=\"pl-kos\">&gt;<\/span><span class=\"pl-kos\">)<\/span> <span class=\"pl-kos\">{<\/span>\r\n    <span style=\"color: #0000ff;\">let<\/span> <span class=\"pl-kos\">[<\/span><span class=\"pl-s1\">lion<\/span><span class=\"pl-kos\">,<\/span> <span class=\"pl-s1\">seal<\/span><span class=\"pl-kos\">]<\/span> <span class=\"pl-c1\">=<\/span> <span style=\"color: #0000ff;\">await<\/span> <span style=\"color: #267F99;\">Promise<\/span><span class=\"pl-kos\">.<\/span><span class=\"pl-en\">all<\/span><span class=\"pl-kos\">(<\/span><span class=\"pl-kos\">[<\/span><span class=\"pl-s1\">lionExhibit<\/span><span class=\"pl-kos\">,<\/span> <span class=\"pl-s1\">sealExhibit<\/span><span class=\"pl-kos\">]<\/span><span class=\"pl-kos\">)<\/span><span class=\"pl-kos\">;<\/span>\r\n    <span class=\"pl-s1\">lion<\/span><span class=\"pl-kos\">.<\/span><span class=\"pl-en\">roar<\/span><span class=\"pl-kos\">(<\/span><span class=\"pl-kos\">)<\/span><span class=\"pl-kos\">;<\/span> <span style=\"color: #148A14;\">\/\/ uh oh<\/span>\r\n<span style=\"color: #148A14;\">\/\/  ~~~~<\/span>\r\n<span style=\"color: #148A14;\">\/\/ Object is possibly 'undefined'.<\/span>\r\n<span class=\"pl-kos\">}<\/span><\/pre>\n<\/div>\n<p>This is strange behavior! The fact that <code>sealExhibit<\/code> contained an <code>undefined<\/code> somehow poisoned type of <code>lion<\/code> to include <code>undefined<\/code>.<\/p>\n<p>Thanks to <a href=\"https:\/\/github.com\/microsoft\/TypeScript\/pull\/34501\">a pull request<\/a> from <a href=\"https:\/\/github.com\/jablko\">Jack Bates<\/a>, this has been fixed with improvements in our inference process in TypeScript 3.9. The above no longer errors. If you&#8217;ve been stuck on older versions of TypeScript due to issues around <code>Promise<\/code>s, we encourage you to give 3.9 a shot!<\/p>\n<h3>What About the <code>awaited<\/code> Type?<\/h3>\n<p>If you&#8217;ve been following our issue tracker and design meeting notes, you might be aware of some work around <a href=\"https:\/\/github.com\/microsoft\/TypeScript\/pull\/35998\">a new type operator called <code>awaited<\/code><\/a>. This goal of this type operator is to accurately model the way that <code>Promise<\/code> unwrapping works in JavaScript.<\/p>\n<p>We initially anticipated shipping <code>awaited<\/code> in TypeScript 3.9, but as we&#8217;ve run early TypeScript builds with existing codebases, we&#8217;ve realized that the feature needs more design work before we can roll it out to everyone smoothly. As a result, we&#8217;ve decided to pull the feature out of our main branch until we feel more confident. We&#8217;ll be experimenting more with the feature, but we won&#8217;t be shipping it as part of this release.<\/p>\n<h2 id=\"speed-improvements\">Speed Improvements<\/h2>\n<p>TypeScript 3.9 ships with many new speed improvements. Our team has been focusing on performance after observing extremely poor editing\/compilation speed with packages like material-ui and styled-components. We&#8217;ve dived deep here, with a series of different pull requests that optimize certain pathological cases involving large unions, intersections, conditional types, and mapped types.<\/p>\n<ul>\n<li><a href=\"https:\/\/github.com\/microsoft\/TypeScript\/pull\/36576\">https:\/\/github.com\/microsoft\/TypeScript\/pull\/36576<\/a><\/li>\n<li><a href=\"https:\/\/github.com\/microsoft\/TypeScript\/pull\/36590\">https:\/\/github.com\/microsoft\/TypeScript\/pull\/36590<\/a><\/li>\n<li><a href=\"https:\/\/github.com\/microsoft\/TypeScript\/pull\/36607\">https:\/\/github.com\/microsoft\/TypeScript\/pull\/36607<\/a><\/li>\n<li><a href=\"https:\/\/github.com\/microsoft\/TypeScript\/pull\/36622\">https:\/\/github.com\/microsoft\/TypeScript\/pull\/36622<\/a><\/li>\n<li><a href=\"https:\/\/github.com\/microsoft\/TypeScript\/pull\/36754\">https:\/\/github.com\/microsoft\/TypeScript\/pull\/36754<\/a><\/li>\n<li><a href=\"https:\/\/github.com\/microsoft\/TypeScript\/pull\/36696\">https:\/\/github.com\/microsoft\/TypeScript\/pull\/36696<\/a><\/li>\n<\/ul>\n<p>Each of these pull requests gains about a 5-10% reduction in compile times on certain codebases. In total, we believe we&#8217;ve achieved around a 25% reduction the <a href=\"https:\/\/github.com\/mui-org\/material-ui\/tree\/8c2abebab524a68e97ffb5cf0c2015a915bd2e12\/packages\/material-ui-styles\"><code>material-ui-styles<\/code><\/a> project&#8217;s compile time. Furthermore, we&#8217;ve gotten feedback from teams at Microsoft that <a href=\"https:\/\/twitter.com\/kenneth_chau\/status\/1257168610759290882\">TypeScript 3.9 has reduced their compile time from 26 seconds to around 10 seconds<\/a>.<\/p>\n<p>We also have some changes to file renaming functionality in editor scenarios. We heard from the Visual Studio Code team that when renaming a file, just figuring out which import statements needed to be updated could take between 5 to 10 seconds. TypeScript 3.9 addresses this issue by <a href=\"https:\/\/github.com\/microsoft\/TypeScript\/pull\/37055\">changing the internals of how the compiler and language service caches file lookups<\/a>.<\/p>\n<p>While there&#8217;s still room for improvement, we hope this work translates to a snappier experience for everyone!<\/p>\n<h2 id=\"ts-expect-error-comments\"><code>\/\/ @ts-expect-error<\/code> Comments<\/h2>\n<p>Imagine that we&#8217;re writing a library in TypeScript and we&#8217;re exporting some function called <code>doStuff<\/code> as part of our public API. The function&#8217;s types declare that it takes two <code>string<\/code>s so that other TypeScript users can get type-checking errors, but it also does a runtime check (maybe only in development builds) to give JavaScript users a helpful error.<\/p>\n<div class=\"highlight highlight-source-ts\">\n<pre class=\"lang:default decode:true\" style=\"background-color: #f0f0f0;padding: 10px;border-radius: 10px;\"><span style=\"color: #0000ff;\">function<\/span> <span class=\"pl-en\">doStuff<\/span><span class=\"pl-kos\">(<\/span><span class=\"pl-s1\">abc<\/span>: <span style=\"color: #0000ff;\">string<\/span><span class=\"pl-kos\">,<\/span> <span class=\"pl-s1\">xyz<\/span>: <span style=\"color: #0000ff;\">string<\/span><span class=\"pl-kos\">)<\/span> <span class=\"pl-kos\">{<\/span>\r\n    <span class=\"pl-en\">assert<\/span><span class=\"pl-kos\">(<\/span><span style=\"color: #0000ff;\">typeof<\/span> <span class=\"pl-s1\">abc<\/span> <span class=\"pl-c1\">===<\/span> <span style=\"color: #a31515;\">\"string\"<\/span><span class=\"pl-kos\">)<\/span><span class=\"pl-kos\">;<\/span>\r\n    <span class=\"pl-en\">assert<\/span><span class=\"pl-kos\">(<\/span><span style=\"color: #0000ff;\">typeof<\/span> <span class=\"pl-s1\">xyz<\/span> <span class=\"pl-c1\">===<\/span> <span style=\"color: #a31515;\">\"string\"<\/span><span class=\"pl-kos\">)<\/span><span class=\"pl-kos\">;<\/span>\r\n\r\n    <span style=\"color: #148A14;\">\/\/ do some stuff<\/span>\r\n<span class=\"pl-kos\">}<\/span><\/pre>\n<\/div>\n<p>So TypeScript users will get a helpful red squiggle and an error message when they misuse this function, and JavaScript users will get an assertion error. We&#8217;d like to test this behavior, so we&#8217;ll write a unit test.<\/p>\n<div class=\"highlight highlight-source-ts\">\n<pre class=\"lang:default decode:true\" style=\"background-color: #f0f0f0;padding: 10px;border-radius: 10px;\"><span class=\"pl-en\">expect<\/span><span class=\"pl-kos\">(<\/span><span class=\"pl-kos\">(<\/span><span class=\"pl-kos\">)<\/span> <span class=\"pl-c1\">=&gt;<\/span> <span class=\"pl-kos\">{<\/span>\r\n    <span class=\"pl-en\">doStuff<\/span><span class=\"pl-kos\">(<\/span><span style=\"color: #09885A;\">123<\/span><span class=\"pl-kos\">,<\/span> <span style=\"color: #09885A;\">456<\/span><span class=\"pl-kos\">)<\/span><span class=\"pl-kos\">;<\/span>\r\n<span class=\"pl-kos\">}<\/span><span class=\"pl-kos\">)<\/span><span class=\"pl-kos\">.<\/span><span class=\"pl-en\">toThrow<\/span><span class=\"pl-kos\">(<\/span><span class=\"pl-kos\">)<\/span><span class=\"pl-kos\">;<\/span><\/pre>\n<\/div>\n<p>Unfortunately if our tests are written in TypeScript, TypeScript will give us an error!<\/p>\n<div class=\"highlight highlight-source-ts\">\n<pre class=\"lang:default decode:true\" style=\"background-color: #f0f0f0;padding: 10px;border-radius: 10px;\">    <span class=\"pl-en\">doStuff<\/span><span class=\"pl-kos\">(<\/span><span style=\"color: #09885A;\">123<\/span><span class=\"pl-kos\">,<\/span> <span style=\"color: #09885A;\">456<\/span><span class=\"pl-kos\">)<\/span><span class=\"pl-kos\">;<\/span>\r\n<span style=\"color: #148A14;\">\/\/          ~~~<\/span>\r\n<span style=\"color: #148A14;\">\/\/ error: Type 'number' is not assignable to type 'string'.<\/span><\/pre>\n<\/div>\n<p>That&#8217;s why TypeScript 3.9 brings a new feature: <code>\/\/ @ts-expect-error<\/code> comments. When a line is prefixed with a <code>\/\/ @ts-expect-error<\/code> comment, TypeScript will suppress that error from being reported; but if there&#8217;s no error, TypeScript will report that <code>\/\/ @ts-expect-error<\/code> wasn&#8217;t necessary.<\/p>\n<p>As a quick example, the following code is okay<\/p>\n<div class=\"highlight highlight-source-ts\">\n<pre class=\"lang:default decode:true\" style=\"background-color: #f0f0f0;padding: 10px;border-radius: 10px;\"><span style=\"color: #148A14;\">\/\/ <span class=\"pl-k\">@ts<\/span>-expect-error<\/span>\r\n<span class=\"pl-smi\">console<\/span><span class=\"pl-kos\">.<\/span><span class=\"pl-en\">log<\/span><span class=\"pl-kos\">(<\/span><span style=\"color: #09885A;\">47<\/span> * <span style=\"color: #a31515;\">\"octopus\"<\/span><span class=\"pl-kos\">)<\/span><span class=\"pl-kos\">;<\/span><\/pre>\n<\/div>\n<p>while the following code<\/p>\n<div class=\"highlight highlight-source-ts\">\n<pre class=\"lang:default decode:true\" style=\"background-color: #f0f0f0;padding: 10px;border-radius: 10px;\"><span style=\"color: #148A14;\">\/\/ <span class=\"pl-k\">@ts<\/span>-expect-error<\/span>\r\n<span class=\"pl-smi\">console<\/span><span class=\"pl-kos\">.<\/span><span class=\"pl-en\">log<\/span><span class=\"pl-kos\">(<\/span><span style=\"color: #09885A;\">1<\/span> <span class=\"pl-c1\">+<\/span> <span style=\"color: #09885A;\">1<\/span><span class=\"pl-kos\">)<\/span><span class=\"pl-kos\">;<\/span><\/pre>\n<\/div>\n<p>results in the error<\/p>\n<pre><code>Unused '@ts-expect-error' directive.\r\n<\/code><\/pre>\n<p>We&#8217;d like to extend a big thanks to <a href=\"https:\/\/github.com\/JoshuaKGoldberg\">Josh Goldberg<\/a>, the contributor who implemented this feature. For more information, you can take a look at <a href=\"https:\/\/github.com\/microsoft\/TypeScript\/pull\/36014\">the <code>ts-expect-error<\/code> pull request<\/a>.<\/p>\n<h3 id=\"what-about-ts-ignore\"><code>ts-ignore<\/code> or <code>ts-expect-error<\/code>?<\/h3>\n<p>In some ways <code>\/\/ @ts-expect-error<\/code> can act as a suppression comment, similar to <code>\/\/ @ts-ignore<\/code>. The difference is that <code>\/\/ @ts-ignore<\/code> will do nothing if the following line is error-free.<\/p>\n<p>You might be tempted to switch existing <code>\/\/ @ts-ignore<\/code> comments over to <code>\/\/ @ts-expect-error<\/code>, and you might be wondering which is appropriate for future code. While it&#8217;s entirely up to you and your team, we have some ideas of which to pick in certain situations.<\/p>\n<p>Pick <code>ts-expect-error<\/code> if:<\/p>\n<ul>\n<li>you&#8217;re writing test code where you actually want the type system to error on an operation<\/li>\n<li>you expect a fix to be coming in fairly quickly and you just need a quick workaround<\/li>\n<li>you&#8217;re in a reasonably-sized project with a proactive team that wants to remove suppression comments as soon affected code is valid again<\/li>\n<\/ul>\n<p>Pick <code>ts-ignore<\/code> if:<\/p>\n<ul>\n<li>you have an a larger project and and new errors have appeared in code with no clear owner<\/li>\n<li>you are in the middle of an upgrade between two different versions of TypeScript, and a line of code errors in one version but not another.<\/li>\n<li>you honestly don&#8217;t have the time to decide which of these options is better.<\/li>\n<\/ul>\n<h2 id=\"uncalled-in-conditionals\">Uncalled Function Checks in Conditional Expressions<\/h2>\n<p>In TypeScript 3.7 we introduced <em>uncalled function checks<\/em> to report an error when you&#8217;ve forgotten to call a function.<\/p>\n<div class=\"highlight highlight-source-ts\">\n<pre class=\"lang:default decode:true\" style=\"background-color: #f0f0f0;padding: 10px;border-radius: 10px;\"><span style=\"color: #0000ff;\">function<\/span> <span class=\"pl-en\">hasImportantPermissions<\/span><span class=\"pl-kos\">(<\/span><span class=\"pl-kos\">)<\/span>: <span style=\"color: #0000ff;\">boolean<\/span> <span class=\"pl-kos\">{<\/span>\r\n    <span style=\"color: #148A14;\">\/\/ ...<\/span>\r\n<span class=\"pl-kos\">}<\/span>\r\n\r\n<span style=\"color: #148A14;\">\/\/ Oops!<\/span>\r\n<span style=\"color: #0000ff;\">if<\/span> <span class=\"pl-kos\">(<\/span><span class=\"pl-s1\">hasImportantPermissions<\/span><span class=\"pl-kos\">)<\/span> <span class=\"pl-kos\">{<\/span>\r\n<span style=\"color: #148A14;\">\/\/  ~~~~~~~~~~~~~~~~~~~~~~~<\/span>\r\n<span style=\"color: #148A14;\">\/\/ This condition will always return true since the function is always defined.<\/span>\r\n<span style=\"color: #148A14;\">\/\/ Did you mean to call it instead?<\/span>\r\n    <span class=\"pl-en\">deleteAllTheImportantFiles<\/span><span class=\"pl-kos\">(<\/span><span class=\"pl-kos\">)<\/span><span class=\"pl-kos\">;<\/span>\r\n<span class=\"pl-kos\">}<\/span><\/pre>\n<\/div>\n<p>However, this error only applied to conditions in <code>if<\/code> statements. Thanks to <a href=\"https:\/\/github.com\/microsoft\/TypeScript\/pull\/36402\">a pull request<\/a> from <a href=\"https:\/\/github.com\/a-tarasyuk\">Alexander Tarasyuk<\/a>, this feature is also now supported in ternary conditionals (i.e. the <code>cond ? trueExpr : falseExpr<\/code> syntax).<\/p>\n<div class=\"highlight highlight-source-ts\">\n<pre class=\"lang:default decode:true\" style=\"background-color: #f0f0f0;padding: 10px;border-radius: 10px;\"><span style=\"color: #0000ff;\">declare<\/span> <span style=\"color: #0000ff;\">function<\/span> <span class=\"pl-s1\">listFilesOfDirectory<\/span><span class=\"pl-kos\">(<\/span><span class=\"pl-s1\">dirPath<\/span>: <span style=\"color: #0000ff;\">string<\/span><span class=\"pl-kos\">)<\/span>: <span style=\"color: #0000ff;\">string<\/span><span class=\"pl-kos\">[<\/span><span class=\"pl-kos\">]<\/span><span class=\"pl-kos\">;<\/span>\r\n<span style=\"color: #0000ff;\">declare<\/span> <span style=\"color: #0000ff;\">function<\/span> <span class=\"pl-s1\">isDirectory<\/span><span class=\"pl-kos\">(<\/span><span class=\"pl-kos\">)<\/span>: <span style=\"color: #0000ff;\">boolean<\/span><span class=\"pl-kos\">;<\/span>\r\n\r\n<span style=\"color: #0000ff;\">function<\/span> <span class=\"pl-en\">getAllFiles<\/span><span class=\"pl-kos\">(<\/span><span class=\"pl-s1\">startFileName<\/span>: <span style=\"color: #0000ff;\">string<\/span><span class=\"pl-kos\">)<\/span> <span class=\"pl-kos\">{<\/span>\r\n    <span style=\"color: #0000ff;\">const<\/span> <span class=\"pl-s1\">result<\/span>: <span style=\"color: #0000ff;\">string<\/span><span class=\"pl-kos\">[<\/span><span class=\"pl-kos\">]<\/span> <span class=\"pl-c1\">=<\/span> <span class=\"pl-kos\">[<\/span><span class=\"pl-kos\">]<\/span><span class=\"pl-kos\">;<\/span>\r\n    <span class=\"pl-en\">traverse<\/span><span class=\"pl-kos\">(<\/span><span class=\"pl-s1\">startFileName<\/span><span class=\"pl-kos\">)<\/span><span class=\"pl-kos\">;<\/span>\r\n    <span style=\"color: #0000ff;\">return<\/span> <span class=\"pl-s1\">result<\/span><span class=\"pl-kos\">;<\/span>\r\n\r\n    <span style=\"color: #0000ff;\">function<\/span> <span class=\"pl-en\">traverse<\/span><span class=\"pl-kos\">(<\/span><span class=\"pl-s1\">currentPath<\/span>: <span style=\"color: #0000ff;\">string<\/span><span class=\"pl-kos\">)<\/span> <span class=\"pl-kos\">{<\/span>\r\n        <span style=\"color: #0000ff;\">return<\/span> <span class=\"pl-s1\">isDirectory<\/span> ?\r\n        <span style=\"color: #148A14;\">\/\/     ~~~~~~~~~~~<\/span>\r\n        <span style=\"color: #148A14;\">\/\/ This condition will always return true<\/span>\r\n        <span style=\"color: #148A14;\">\/\/ since the function is always defined.<\/span>\r\n        <span style=\"color: #148A14;\">\/\/ Did you mean to call it instead?<\/span>\r\n            <span class=\"pl-en\">listFilesOfDirectory<\/span><span class=\"pl-kos\">(<\/span><span class=\"pl-s1\">currentPath<\/span><span class=\"pl-kos\">)<\/span><span class=\"pl-kos\">.<\/span><span class=\"pl-en\">forEach<\/span><span class=\"pl-kos\">(<\/span><span class=\"pl-s1\">traverse<\/span><span class=\"pl-kos\">)<\/span> :\r\n            <span class=\"pl-s1\">result<\/span><span class=\"pl-kos\">.<\/span><span class=\"pl-en\">push<\/span><span class=\"pl-kos\">(<\/span><span class=\"pl-s1\">currentPath<\/span><span class=\"pl-kos\">)<\/span><span class=\"pl-kos\">;<\/span>\r\n    <span class=\"pl-kos\">}<\/span>\r\n<span class=\"pl-kos\">}<\/span><\/pre>\n<\/div>\n<p>Alexander further improved the uncalled function checking experience <a href=\"https:\/\/github.com\/microsoft\/TypeScript\/pull\/37152\">by adding a quick fix<\/a>!<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/typescript\/wp-content\/uploads\/sites\/11\/2020\/05\/uncalledFunctionQuickFix.png\" alt=\"Quick fix for uncalled function checks\" \/><\/p>\n<h2 id=\"editor-improvements\">Editor Improvements<\/h2>\n<p>The TypeScript compiler not only powers the TypeScript editing experience in most major editors, it also powers the JavaScript experience in the Visual Studio family of editors and more. Using new TypeScript\/JavaScript functionality in your editor will differ depending on your editor, but<\/p>\n<ul>\n<li>Visual Studio Code supports <a href=\"https:\/\/code.visualstudio.com\/docs\/typescript\/typescript-compiling#_using-newer-typescript-versions\" rel=\"nofollow\">selecting different versions of TypeScript<\/a>. Alternatively, there&#8217;s the <a href=\"https:\/\/marketplace.visualstudio.com\/items?itemName=ms-vscode.vscode-typescript-next\" rel=\"nofollow\">JavaScript\/TypeScript Nightly Extension<\/a> to stay on the bleeding edge (which is typically very stable).<\/li>\n<li>Visual Studio 2017\/2019 have <a href=\"https:\/\/marketplace.visualstudio.com\/items?itemName=TypeScriptTeam.TypeScript-39\" rel=\"nofollow\">the SDK installers above<\/a> and <a href=\"https:\/\/www.nuget.org\/packages\/Microsoft.TypeScript.MSBuild\" rel=\"nofollow\">MSBuild installs<\/a>.<\/li>\n<li>Sublime Text 3 supports <a href=\"https:\/\/github.com\/microsoft\/TypeScript-Sublime-Plugin#note-using-different-versions-of-typescript\">selecting different versions of TypeScript<\/a><\/li>\n<\/ul>\n<h3 id=\"cjs-auto-imports\">CommonJS Auto-Imports in JavaScript<\/h3>\n<p>One great new improvement is in auto-imports in JavaScript files using CommonJS modules.<\/p>\n<p>In older versions, TypeScript always assumed that regardless of your file, you wanted an ECMAScript-style import like<\/p>\n<div class=\"highlight highlight-source-js\">\n<pre class=\"lang:default decode:true\" style=\"background-color: #f0f0f0;padding: 10px;border-radius: 10px;\"><span style=\"color: #0000ff;\">import<\/span> * <span style=\"color: #0000ff;\">as<\/span> <span class=\"pl-s1\">fs<\/span> <span style=\"color: #0000ff;\">from<\/span> <span style=\"color: #a31515;\">\"fs\"<\/span><span class=\"pl-kos\">;<\/span><\/pre>\n<\/div>\n<p>However, not everyone is targeting ECMAScript-style modules when writing JavaScript files. Plenty of users still use CommonJS-style <code>require(...)<\/code> imports like so<\/p>\n<div class=\"highlight highlight-source-js\">\n<pre class=\"lang:default decode:true\" style=\"background-color: #f0f0f0;padding: 10px;border-radius: 10px;\"><span style=\"color: #0000ff;\">const<\/span> <span class=\"pl-s1\">fs<\/span> <span class=\"pl-c1\">=<\/span> <span class=\"pl-en\">require<\/span><span class=\"pl-kos\">(<\/span><span style=\"color: #a31515;\">\"fs\"<\/span><span class=\"pl-kos\">)<\/span><span class=\"pl-kos\">;<\/span><\/pre>\n<\/div>\n<p>TypeScript now automatically detects the types of imports you&#8217;re using to keep your file&#8217;s style clean and consistent.<\/p>\n<p><video autoplay loop style=\"width: 100%;\" src=\"https:\/\/devblogs.microsoft.com\/typescript\/wp-content\/uploads\/sites\/11\/2020\/03\/ERkaliGU0AA5anJ1.mp4\"><\/video><\/p>\n<p>For more details on the change, see <a href=\"https:\/\/github.com\/microsoft\/TypeScript\/pull\/37027\">the corresponding pull request<\/a>.<\/p>\n<h3 id=\"preserve-newlines\">Code Actions Preserve Newlines<\/h3>\n<p>TypeScript&#8217;s refactorings and quick fixes often didn&#8217;t do a great job of preserving newlines. As a really basic example, take the following code.<\/p>\n<div class=\"highlight highlight-source-ts\">\n<pre class=\"lang:default decode:true\" style=\"background-color: #f0f0f0;padding: 10px;border-radius: 10px;\"><span style=\"color: #0000ff;\">const<\/span> <span class=\"pl-s1\">maxValue<\/span> <span class=\"pl-c1\">=<\/span> <span style=\"color: #09885A;\">100<\/span><span class=\"pl-kos\">;<\/span>\r\n\r\n<span style=\"color: #148A14;\">\/*start*\/<\/span>\r\n<span style=\"color: #0000ff;\">for<\/span> <span class=\"pl-kos\">(<\/span><span style=\"color: #0000ff;\">let<\/span> <span class=\"pl-s1\">i<\/span> <span class=\"pl-c1\">=<\/span> <span style=\"color: #09885A;\">0<\/span><span class=\"pl-kos\">;<\/span> <span class=\"pl-s1\">i<\/span> &lt;= <span class=\"pl-s1\">maxValue<\/span><span class=\"pl-kos\">;<\/span> <span class=\"pl-s1\">i<\/span><span class=\"pl-c1\">++<\/span><span class=\"pl-kos\">)<\/span> <span class=\"pl-kos\">{<\/span>\r\n    <span style=\"color: #148A14;\">\/\/ First get the squared value.<\/span>\r\n    <span style=\"color: #0000ff;\">let<\/span> <span class=\"pl-s1\">square<\/span> <span class=\"pl-c1\">=<\/span> <span class=\"pl-s1\">i<\/span> ** <span style=\"color: #09885A;\">2<\/span><span class=\"pl-kos\">;<\/span>\r\n\r\n    <span style=\"color: #148A14;\">\/\/ Now print the squared value.<\/span>\r\n    <span class=\"pl-smi\">console<\/span><span class=\"pl-kos\">.<\/span><span class=\"pl-en\">log<\/span><span class=\"pl-kos\">(<\/span><span class=\"pl-s1\">square<\/span><span class=\"pl-kos\">)<\/span><span class=\"pl-kos\">;<\/span>\r\n<span class=\"pl-kos\">}<\/span>\r\n<span style=\"color: #148A14;\">\/*end*\/<\/span><\/pre>\n<\/div>\n<p>If we highlighted the range from <code>\/*start*\/<\/code> to <code>\/*end*\/<\/code> in our editor to extract to a new function, we&#8217;d end up with code like the following.<\/p>\n<div class=\"highlight highlight-source-ts\">\n<pre class=\"lang:default decode:true\" style=\"background-color: #f0f0f0;padding: 10px;border-radius: 10px;\"><span style=\"color: #0000ff;\">const<\/span> <span class=\"pl-s1\">maxValue<\/span> <span class=\"pl-c1\">=<\/span> <span style=\"color: #09885A;\">100<\/span><span class=\"pl-kos\">;<\/span>\r\n\r\n<span class=\"pl-en\">printSquares<\/span><span class=\"pl-kos\">(<\/span><span class=\"pl-kos\">)<\/span><span class=\"pl-kos\">;<\/span>\r\n\r\n<span style=\"color: #0000ff;\">function<\/span> <span class=\"pl-en\">printSquares<\/span><span class=\"pl-kos\">(<\/span><span class=\"pl-kos\">)<\/span> <span class=\"pl-kos\">{<\/span>\r\n    <span style=\"color: #0000ff;\">for<\/span> <span class=\"pl-kos\">(<\/span><span style=\"color: #0000ff;\">let<\/span> <span class=\"pl-s1\">i<\/span> <span class=\"pl-c1\">=<\/span> <span style=\"color: #09885A;\">0<\/span><span class=\"pl-kos\">;<\/span> <span class=\"pl-s1\">i<\/span> &lt;= <span class=\"pl-s1\">maxValue<\/span><span class=\"pl-kos\">;<\/span> <span class=\"pl-s1\">i<\/span><span class=\"pl-c1\">++<\/span><span class=\"pl-kos\">)<\/span> <span class=\"pl-kos\">{<\/span>\r\n        <span style=\"color: #148A14;\">\/\/ First get the squared value.<\/span>\r\n        <span style=\"color: #0000ff;\">let<\/span> <span class=\"pl-s1\">square<\/span> <span class=\"pl-c1\">=<\/span> <span class=\"pl-s1\">i<\/span> ** <span style=\"color: #09885A;\">2<\/span><span class=\"pl-kos\">;<\/span>\r\n        <span style=\"color: #148A14;\">\/\/ Now print the squared value.<\/span>\r\n        <span class=\"pl-smi\">console<\/span><span class=\"pl-kos\">.<\/span><span class=\"pl-en\">log<\/span><span class=\"pl-kos\">(<\/span><span class=\"pl-s1\">square<\/span><span class=\"pl-kos\">)<\/span><span class=\"pl-kos\">;<\/span>\r\n    <span class=\"pl-kos\">}<\/span>\r\n<span class=\"pl-kos\">}<\/span><\/pre>\n<\/div>\n<p><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/typescript\/wp-content\/uploads\/sites\/11\/2020\/03\/printSquaresWithoutNewlines-3.9.gif.gif\" alt=\"Extracting the for loop to a function in older versions of TypeScript. A newline is not preserved.\" \/><\/p>\n<p>That&#8217;s not ideal &#8211; we had a blank line between each statement in our <code>for<\/code> loop, but the refactoring got rid of it! TypeScript 3.9 does a little more work to preserve what we write.<\/p>\n<div class=\"highlight highlight-source-ts\">\n<pre class=\"lang:default decode:true\" style=\"background-color: #f0f0f0;padding: 10px;border-radius: 10px;\"><span style=\"color: #0000ff;\">const<\/span> <span class=\"pl-s1\">maxValue<\/span> <span class=\"pl-c1\">=<\/span> <span style=\"color: #09885A;\">100<\/span><span class=\"pl-kos\">;<\/span>\r\n\r\n<span class=\"pl-en\">printSquares<\/span><span class=\"pl-kos\">(<\/span><span class=\"pl-kos\">)<\/span><span class=\"pl-kos\">;<\/span>\r\n\r\n<span style=\"color: #0000ff;\">function<\/span> <span class=\"pl-en\">printSquares<\/span><span class=\"pl-kos\">(<\/span><span class=\"pl-kos\">)<\/span> <span class=\"pl-kos\">{<\/span>\r\n    <span style=\"color: #0000ff;\">for<\/span> <span class=\"pl-kos\">(<\/span><span style=\"color: #0000ff;\">let<\/span> <span class=\"pl-s1\">i<\/span> <span class=\"pl-c1\">=<\/span> <span style=\"color: #09885A;\">0<\/span><span class=\"pl-kos\">;<\/span> <span class=\"pl-s1\">i<\/span> &lt;= <span class=\"pl-s1\">maxValue<\/span><span class=\"pl-kos\">;<\/span> <span class=\"pl-s1\">i<\/span><span class=\"pl-c1\">++<\/span><span class=\"pl-kos\">)<\/span> <span class=\"pl-kos\">{<\/span>\r\n        <span style=\"color: #148A14;\">\/\/ First get the squared value.<\/span>\r\n        <span style=\"color: #0000ff;\">let<\/span> <span class=\"pl-s1\">square<\/span> <span class=\"pl-c1\">=<\/span> <span class=\"pl-s1\">i<\/span> ** <span style=\"color: #09885A;\">2<\/span><span class=\"pl-kos\">;<\/span>\r\n\r\n        <span style=\"color: #148A14;\">\/\/ Now print the squared value.<\/span>\r\n        <span class=\"pl-smi\">console<\/span><span class=\"pl-kos\">.<\/span><span class=\"pl-en\">log<\/span><span class=\"pl-kos\">(<\/span><span class=\"pl-s1\">square<\/span><span class=\"pl-kos\">)<\/span><span class=\"pl-kos\">;<\/span>\r\n    <span class=\"pl-kos\">}<\/span>\r\n<span class=\"pl-kos\">}<\/span><\/pre>\n<\/div>\n<p><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/typescript\/wp-content\/uploads\/sites\/11\/2020\/03\/printSquaresWithNewlines-3.9.gif.gif\" alt=\"Extracting the for loop to a function in TypeScript 3.9. A newline is preserved.\" \/><\/p>\n<p>You can see more about the implementation <a href=\"https:\/\/github.com\/microsoft\/TypeScript\/pull\/36688\">in this pull request<\/a><\/p>\n<h3 id=\"missing-returns\">Quick Fixes for Missing Return Expressions<\/h3>\n<p>There are occasions where we might forget to return the value of the last statement in a function, especially when adding curly braces to arrow functions.<\/p>\n<div class=\"highlight highlight-source-ts\">\n<pre class=\"lang:default decode:true\" style=\"background-color: #f0f0f0;padding: 10px;border-radius: 10px;\"><span style=\"color: #148A14;\">\/\/ before<\/span>\r\n<span style=\"color: #0000ff;\">let<\/span> <span class=\"pl-en\">f1<\/span> <span class=\"pl-c1\">=<\/span> <span class=\"pl-kos\">(<\/span><span class=\"pl-kos\">)<\/span> <span class=\"pl-c1\">=&gt;<\/span> <span style=\"color: #09885A;\">42<\/span>\r\n\r\n<span style=\"color: #148A14;\">\/\/ oops - not the same!<\/span>\r\n<span style=\"color: #0000ff;\">let<\/span> <span class=\"pl-en\">f2<\/span> <span class=\"pl-c1\">=<\/span> <span class=\"pl-kos\">(<\/span><span class=\"pl-kos\">)<\/span> <span class=\"pl-c1\">=&gt;<\/span> <span class=\"pl-kos\">{<\/span> <span style=\"color: #09885A;\">42<\/span> <span class=\"pl-kos\">}<\/span><\/pre>\n<\/div>\n<p>Thanks to <a href=\"https:\/\/github.com\/microsoft\/TypeScript\/pull\/26434\">a pull request<\/a> from community member <a href=\"https:\/\/github.com\/Kingwl\">Wenlu Wang<\/a>, TypeScript can provide a quick-fix to add missing <code>return<\/code> statements, remove curly braces, or add parentheses to arrow function bodies that look suspiciously like object literals.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/typescript\/wp-content\/uploads\/sites\/11\/2020\/04\/missingReturnValue-3-9.gif\" alt=\"TypeScript fixing an error where no expression is returned by adding a return statement or removing curly braces.\" \/><\/p>\n<h3 id=\"solution-style-tsconfig\">Support for &#8220;Solution Style&#8221; <code>tsconfig.json<\/code> Files<\/h3>\n<p>Editors need to figure out which configuration file a file belongs to so that it can apply the appropriate options and figure out which other files are included in the current &#8220;project&#8221;. By default, editors powered by TypeScript&#8217;s language server do this by walking up each parent directory to find a <code>tsconfig.json<\/code>.<\/p>\n<p>One case where this slightly fell over is when a <code>tsconfig.json<\/code> simply existed to reference other <code>tsconfig.json<\/code> files.<\/p>\n<div class=\"highlight highlight-source-js\">\n<pre class=\"lang:default decode:true\" style=\"background-color: #f0f0f0;padding: 10px;border-radius: 10px;\"><span style=\"color: #148A14;\">\/\/ tsconfig.json<\/span>\r\n<span class=\"pl-kos\">{<\/span>\r\n    <span style=\"color: #a31515;\">\"files\"<\/span>: <span class=\"pl-kos\">[<\/span><span class=\"pl-kos\">]<\/span><span class=\"pl-kos\">,<\/span>\r\n    <span style=\"color: #a31515;\">\"references\"<\/span>: <span class=\"pl-kos\">[<\/span>\r\n        <span class=\"pl-kos\">{<\/span> <span style=\"color: #a31515;\">\"path\"<\/span>: <span style=\"color: #a31515;\">\".\/tsconfig.shared.json\"<\/span> <span class=\"pl-kos\">}<\/span><span class=\"pl-kos\">,<\/span>\r\n        <span class=\"pl-kos\">{<\/span> <span style=\"color: #a31515;\">\"path\"<\/span>: <span style=\"color: #a31515;\">\".\/tsconfig.frontend.json\"<\/span> <span class=\"pl-kos\">}<\/span><span class=\"pl-kos\">,<\/span>\r\n        <span class=\"pl-kos\">{<\/span> <span style=\"color: #a31515;\">\"path\"<\/span>: <span style=\"color: #a31515;\">\".\/tsconfig.backend.json\"<\/span> <span class=\"pl-kos\">}<\/span><span class=\"pl-kos\">,<\/span>\r\n    <span class=\"pl-kos\">]<\/span>\r\n<span class=\"pl-kos\">}<\/span><\/pre>\n<\/div>\n<p>This file that really does nothing but manage other project files is often called a &#8220;solution&#8221; in some environments. Here, none of these <code>tsconfig.*.json<\/code> files get picked up by the server, but we&#8217;d really like the language server to understand that the current <code>.ts<\/code> file probably belongs to one of the mentioned projects in this root <code>tsconfig.json<\/code>.<\/p>\n<p>TypeScript 3.9 adds support to editing scenarios for this configuration. For more details, take a look at <a href=\"https:\/\/github.com\/microsoft\/TypeScript\/pull\/37239\">the pull request that added this functionality<\/a>.<\/p>\n<h2 id=\"breaking-changes\">Breaking Changes<\/h2>\n<h3>Parsing Differences in Optional Chaining and Non-Null Assertions<\/h3>\n<p>TypeScript recently implemented the optional chaining operator, but we&#8217;ve received user feedback that the behavior of optional chaining (<code>?.<\/code>) with the non-null assertion operator (<code>!<\/code>) is extremely counter-intuitive.<\/p>\n<p>Specifically, in previous versions, the code<\/p>\n<div class=\"highlight highlight-source-ts\">\n<pre class=\"lang:default decode:true\" style=\"background-color: #f0f0f0;padding: 10px;border-radius: 10px;\"><span class=\"pl-s1\">foo<\/span>?<span class=\"pl-kos\">.<\/span><span class=\"pl-c1\">bar<\/span>!<span class=\"pl-kos\">.<\/span><span class=\"pl-c1\">baz<\/span><\/pre>\n<\/div>\n<p>was interpreted to be equivalent to the following JavaScript.<\/p>\n<div class=\"highlight highlight-source-js\">\n<pre class=\"lang:default decode:true\" style=\"background-color: #f0f0f0;padding: 10px;border-radius: 10px;\"><span class=\"pl-kos\">(<\/span><span class=\"pl-s1\">foo<\/span>?<span class=\"pl-kos\">.<\/span><span class=\"pl-c1\">bar<\/span><span class=\"pl-kos\">)<\/span><span class=\"pl-kos\">.<\/span><span class=\"pl-c1\">baz<\/span><\/pre>\n<\/div>\n<p>In the above code the parentheses stop the &#8220;short-circuiting&#8221; behavior of optional chaining, so if <code>foo<\/code> is <code>undefined<\/code>, accessing <code>baz<\/code> will cause a runtime error.<\/p>\n<p>The Babel team who pointed this behavior out, and most users who provided feedback to us, believe that this behavior is wrong. We do too! The thing we heard the most was that the <code>!<\/code> operator should just &#8220;disappear&#8221; since the intent was to remove <code>null<\/code> and <code>undefined<\/code> from the type of <code>bar<\/code>.<\/p>\n<p>In other words, most people felt that the original snippet should be interpreted as<\/p>\n<div class=\"highlight highlight-source-js\">\n<pre class=\"lang:default decode:true\" style=\"background-color: #f0f0f0;padding: 10px;border-radius: 10px;\"><span class=\"pl-s1\">foo<\/span>?<span class=\"pl-kos\">.<\/span><span class=\"pl-c1\">bar<\/span><span class=\"pl-kos\">.<\/span><span class=\"pl-c1\">baz<\/span><\/pre>\n<\/div>\n<p>which just evaluates to <code>undefined<\/code> when <code>foo<\/code> is <code>undefined<\/code>.<\/p>\n<p>This is a breaking change, but we believe most code was written with the new interpretation in mind. Users who want to revert to the old behavior can add explicit parentheses around the left side of the <code>!<\/code> operator.<\/p>\n<div class=\"highlight highlight-source-ts\">\n<pre class=\"lang:default decode:true\" style=\"background-color: #f0f0f0;padding: 10px;border-radius: 10px;\"><span class=\"pl-kos\">(<\/span><span class=\"pl-s1\">foo<\/span>?<span class=\"pl-kos\">.<\/span><span class=\"pl-s1\">bar<\/span><span class=\"pl-kos\">)<\/span>!<span class=\"pl-kos\">.<\/span><span class=\"pl-c1\">baz<\/span><\/pre>\n<\/div>\n<h3><code>}<\/code> and <code>&gt;<\/code> are Now Invalid JSX Text Characters<\/h3>\n<p>The JSX Specification forbids the use of the <code>}<\/code> and <code>&gt;<\/code> characters in text positions. TypeScript and Babel have both decided to enforce this rule to be more comformant. The new way to insert these characters is to use an HTML escape code (e.g. <code>&lt;div&gt; 2 &amp;gt; 1 &lt;\/div&gt;<\/code>) or insert an expression with a string literal (e.g. <code>&lt;div&gt; 2 {\"&gt;\"} 1 &lt;\/div&gt;<\/code>).<\/p>\n<p>Luckily, thanks to the <a href=\"https:\/\/github.com\/microsoft\/TypeScript\/pull\/36636\">pull request<\/a> enforcing this from <a href=\"https:\/\/github.com\/bradzacher\">Brad Zacher<\/a>, you&#8217;ll get an error message along the lines of<\/p>\n<pre><code>Unexpected token. Did you mean `{'&gt;'}` or `&amp;gt;`?\r\nUnexpected token. Did you mean `{'}'}` or `&amp;rbrace;`?\r\n<\/code><\/pre>\n<p>For example:<\/p>\n<div class=\"highlight highlight-source-tsx\">\n<pre class=\"lang:default decode:true\" style=\"background-color: #f0f0f0;padding: 10px;border-radius: 10px;\"><span style=\"color: #0000ff;\">let<\/span> <span class=\"pl-s1\">directions<\/span> <span class=\"pl-c1\">=<\/span> <span class=\"pl-c1\">&lt;<\/span><span class=\"pl-ent\">div<\/span><span class=\"pl-c1\">&gt;<\/span>Navigate to: Menu Bar <span class=\"pl-c1\">&gt;<\/span> <span style=\"color: #267F99;\">Tools<\/span> <span class=\"pl-c1\">&gt;<\/span> <span style=\"color: #267F99;\">Options<\/span><span class=\"pl-c1\">&lt;<\/span>\/div&gt;\r\n<span style=\"color: #148A14;\">\/\/                                          ~       ~<\/span>\r\n<span style=\"color: #148A14;\">\/\/ Unexpected token. Did you mean `{'&gt;'}` or `&amp;gt;`?<\/span><\/pre>\n<\/div>\n<p>That error message came with a handy quick fix, and thanks to <a href=\"https:\/\/github.com\/a-tarasyuk\">Alexander Tarasyuk<\/a>, <a href=\"https:\/\/github.com\/microsoft\/TypeScript\/pull\/37436\">you can apply these changes in bulk<\/a> if you have a lot of errors.<\/p>\n<h3>Stricter Checks on Intersections and Optional Properties<\/h3>\n<p>Generally, an intersection type like <code>A &amp; B<\/code> is assignable to <code>C<\/code> if either <code>A<\/code> or <code>B<\/code> is assignable to <code>C<\/code>; however, sometimes that has problems with optional properties. For example, take the following:<\/p>\n<div class=\"highlight highlight-source-ts\">\n<pre class=\"lang:default decode:true\" style=\"background-color: #f0f0f0;padding: 10px;border-radius: 10px;\"><span style=\"color: #0000ff;\">interface<\/span> <span style=\"color: #267F99;\">A<\/span> <span class=\"pl-kos\">{<\/span>\r\n    <span class=\"pl-c1\">a<\/span>: <span style=\"color: #0000ff;\">number<\/span><span class=\"pl-kos\">;<\/span> <span style=\"color: #148A14;\">\/\/ notice this is 'number'<\/span>\r\n<span class=\"pl-kos\">}<\/span>\r\n\r\n<span style=\"color: #0000ff;\">interface<\/span> <span style=\"color: #267F99;\">B<\/span> <span class=\"pl-kos\">{<\/span>\r\n    <span class=\"pl-c1\">b<\/span>: <span style=\"color: #0000ff;\">string<\/span><span class=\"pl-kos\">;<\/span>\r\n<span class=\"pl-kos\">}<\/span>\r\n\r\n<span style=\"color: #0000ff;\">interface<\/span> <span style=\"color: #267F99;\">C<\/span> <span class=\"pl-kos\">{<\/span>\r\n    <span class=\"pl-c1\">a<\/span>?: <span style=\"color: #0000ff;\">boolean<\/span><span class=\"pl-kos\">;<\/span> <span style=\"color: #148A14;\">\/\/ notice this is 'boolean'<\/span>\r\n    <span class=\"pl-c1\">b<\/span>: <span style=\"color: #0000ff;\">string<\/span><span class=\"pl-kos\">;<\/span>\r\n<span class=\"pl-kos\">}<\/span>\r\n\r\n<span style=\"color: #0000ff;\">declare<\/span> <span style=\"color: #0000ff;\">let<\/span> <span class=\"pl-s1\">x<\/span>: <span style=\"color: #267F99;\">A<\/span> &amp; <span style=\"color: #267F99;\">B<\/span><span class=\"pl-kos\">;<\/span>\r\n<span style=\"color: #0000ff;\">declare<\/span> <span style=\"color: #0000ff;\">let<\/span> <span class=\"pl-s1\">y<\/span>: <span style=\"color: #267F99;\">C<\/span><span class=\"pl-kos\">;<\/span>\r\n\r\n<span class=\"pl-s1\">y<\/span> <span class=\"pl-c1\">=<\/span> <span class=\"pl-s1\">x<\/span><span class=\"pl-kos\">;<\/span><\/pre>\n<\/div>\n<p>In previous versions of TypeScript, this was allowed because while <code>A<\/code> was totally incompatible with <code>C<\/code>, <code>B<\/code> <em>was<\/em> compatible with <code>C<\/code>.<\/p>\n<p>In TypeScript 3.9, so long as every type in an intersection is a concrete object type, the type system will consider all of the properties at once. As a result, TypeScript will see that the <code>a<\/code> property of <code>A &amp; B<\/code> is incompatible with that of <code>C<\/code>:<\/p>\n<pre><code>Type 'A &amp; B' is not assignable to type 'C'.\r\n  Types of property 'a' are incompatible.\r\n    Type 'number' is not assignable to type 'boolean | undefined'.\r\n<\/code><\/pre>\n<p>For more information on this change, <a href=\"https:\/\/github.com\/microsoft\/TypeScript\/pull\/37195\">see the corresponding pull request<\/a>.<\/p>\n<h3>Intersections Reduced By Discriminant Properties<\/h3>\n<p>There are a few cases where you might end up with types that describe values that just don&#8217;t exist. For example<\/p>\n<div class=\"highlight highlight-source-ts\">\n<pre class=\"lang:default decode:true\" style=\"background-color: #f0f0f0;padding: 10px;border-radius: 10px;\"><span style=\"color: #0000ff;\">declare<\/span> <span style=\"color: #0000ff;\">function<\/span> <span class=\"pl-s1\">smushObjects<\/span><span class=\"pl-c1\">&lt;<\/span><span style=\"color: #267F99;\">T<\/span><span class=\"pl-kos\">,<\/span> <span style=\"color: #267F99;\">U<\/span><span class=\"pl-c1\">&gt;<\/span><span class=\"pl-kos\">(<\/span><span class=\"pl-s1\">x<\/span>: <span style=\"color: #267F99;\">T<\/span><span class=\"pl-kos\">,<\/span> <span class=\"pl-s1\">y<\/span>: <span style=\"color: #267F99;\">U<\/span><span class=\"pl-kos\">)<\/span>: <span style=\"color: #267F99;\">T<\/span> &amp; <span style=\"color: #267F99;\">U<\/span><span class=\"pl-kos\">;<\/span>\r\n\r\n<span style=\"color: #0000ff;\">interface<\/span> <span style=\"color: #267F99;\">Circle<\/span> <span class=\"pl-kos\">{<\/span>\r\n    <span class=\"pl-c1\">kind<\/span>: <span style=\"color: #a31515;\">\"circle\"<\/span><span class=\"pl-kos\">;<\/span>\r\n    <span class=\"pl-c1\">radius<\/span>: <span style=\"color: #0000ff;\">number<\/span><span class=\"pl-kos\">;<\/span>\r\n<span class=\"pl-kos\">}<\/span>\r\n\r\n<span style=\"color: #0000ff;\">interface<\/span> <span style=\"color: #267F99;\">Square<\/span> <span class=\"pl-kos\">{<\/span>\r\n    <span class=\"pl-c1\">kind<\/span>: <span style=\"color: #a31515;\">\"square\"<\/span><span class=\"pl-kos\">;<\/span>\r\n    <span class=\"pl-c1\">sideLength<\/span>: <span style=\"color: #0000ff;\">number<\/span><span class=\"pl-kos\">;<\/span>\r\n<span class=\"pl-kos\">}<\/span>\r\n\r\n<span style=\"color: #0000ff;\">declare<\/span> <span style=\"color: #0000ff;\">let<\/span> <span class=\"pl-s1\">x<\/span>: <span style=\"color: #267F99;\">Circle<\/span><span class=\"pl-kos\">;<\/span>\r\n<span style=\"color: #0000ff;\">declare<\/span> <span style=\"color: #0000ff;\">let<\/span> <span class=\"pl-s1\">y<\/span>: <span style=\"color: #267F99;\">Square<\/span><span class=\"pl-kos\">;<\/span>\r\n\r\n<span style=\"color: #0000ff;\">let<\/span> <span class=\"pl-s1\">z<\/span> <span class=\"pl-c1\">=<\/span> <span class=\"pl-en\">smushObjects<\/span><span class=\"pl-kos\">(<\/span><span class=\"pl-s1\">x<\/span><span class=\"pl-kos\">,<\/span> <span class=\"pl-s1\">y<\/span><span class=\"pl-kos\">)<\/span><span class=\"pl-kos\">;<\/span>\r\n<span class=\"pl-smi\">console<\/span><span class=\"pl-kos\">.<\/span><span class=\"pl-en\">log<\/span><span class=\"pl-kos\">(<\/span><span class=\"pl-s1\">z<\/span><span class=\"pl-kos\">.<\/span><span class=\"pl-c1\">kind<\/span><span class=\"pl-kos\">)<\/span><span class=\"pl-kos\">;<\/span><\/pre>\n<\/div>\n<p>This code is slightly weird because there&#8217;s really no way to create an intersection of a <code>Circle<\/code> and a <code>Square<\/code> &#8211; they have two incompatible <code>kind<\/code> fields. In previous versions of TypeScript, this code was allowed and the type of <code>kind<\/code> itself was <code>never<\/code> because <code>\"circle\" &amp; \"square\"<\/code> described a set of values that could <code>never<\/code> exist.<\/p>\n<p>In TypeScript 3.9, the type system is more aggressive here &#8211; it notices that it&#8217;s impossible to intersect <code>Circle<\/code> and <code>Square<\/code> because of their <code>kind<\/code> properties. So instead of collapsing the type of <code>z.kind<\/code> to <code>never<\/code>, it collapses the type of <code>z<\/code> itself (<code>Circle &amp; Square<\/code>) to <code>never<\/code>. That means the above code now errors with:<\/p>\n<pre><code>Property 'kind' does not exist on type 'never'.\r\n<\/code><\/pre>\n<p>Most of the breaks we observed seem to correspond with slightly incorrect type declarations. For more details, <a href=\"https:\/\/github.com\/microsoft\/TypeScript\/pull\/36696\">see the original pull request<\/a>.<\/p>\n<h3>Getters\/Setters are No Longer Enumerable<\/h3>\n<p>In older versions of TypeScript, <code>get<\/code> and <code>set<\/code> accessors in classes were emitted in a way that made them enumerable; however, this wasn&#8217;t compliant with the ECMAScript specification which states that they must be non-enumerable. As a result, TypeScript code that targeted ES5 and ES2015 could differ in behavior.<\/p>\n<p>Thanks to <a href=\"https:\/\/github.com\/microsoft\/TypeScript\/pull\/32264\">a pull request<\/a> from GitHub user <a href=\"https:\/\/github.com\/pathurs\">pathurs<\/a>, TypeScript 3.9 now conforms more closely with ECMAScript in this regard.<\/p>\n<h3>Type Parameters That Extend <code>any<\/code> No Longer Act as <code>any<\/code><\/h3>\n<p>In previous versions of TypeScript, a type parameter constrained to <code>any<\/code> could be treated as <code>any<\/code>.<\/p>\n<div class=\"highlight highlight-source-ts\">\n<pre class=\"lang:default decode:true\" style=\"background-color: #f0f0f0;padding: 10px;border-radius: 10px;\"><span style=\"color: #0000ff;\">function<\/span> <span class=\"pl-en\">foo<\/span><span class=\"pl-c1\">&lt;<\/span><span style=\"color: #267F99;\">T<\/span> <span style=\"color: #0000ff;\">extends<\/span> <span style=\"color: #0000ff;\">any<\/span><span class=\"pl-c1\">&gt;<\/span><span class=\"pl-kos\">(<\/span><span class=\"pl-s1\">arg<\/span>: <span style=\"color: #267F99;\">T<\/span><span class=\"pl-kos\">)<\/span> <span class=\"pl-kos\">{<\/span>\r\n    <span class=\"pl-s1\">arg<\/span><span class=\"pl-kos\">.<\/span><span class=\"pl-c1\">spfjgerijghoied<\/span><span class=\"pl-kos\">;<\/span> <span style=\"color: #148A14;\">\/\/ no error!<\/span>\r\n<span class=\"pl-kos\">}<\/span><\/pre>\n<\/div>\n<p>This was an oversight, so TypeScript 3.9 takes a more conservative approach and issues an error on these questionable operations.<\/p>\n<div class=\"highlight highlight-source-ts\">\n<pre class=\"lang:default decode:true\" style=\"background-color: #f0f0f0;padding: 10px;border-radius: 10px;\"><span style=\"color: #0000ff;\">function<\/span> <span class=\"pl-en\">foo<\/span><span class=\"pl-c1\">&lt;<\/span><span style=\"color: #267F99;\">T<\/span> <span style=\"color: #0000ff;\">extends<\/span> <span style=\"color: #0000ff;\">any<\/span><span class=\"pl-c1\">&gt;<\/span><span class=\"pl-kos\">(<\/span><span class=\"pl-s1\">arg<\/span>: <span style=\"color: #267F99;\">T<\/span><span class=\"pl-kos\">)<\/span> <span class=\"pl-kos\">{<\/span>\r\n    <span class=\"pl-s1\">arg<\/span><span class=\"pl-kos\">.<\/span><span class=\"pl-c1\">spfjgerijghoied<\/span><span class=\"pl-kos\">;<\/span>\r\n    <span style=\"color: #148A14;\">\/\/  ~~~~~~~~~~~~~~~<\/span>\r\n    <span style=\"color: #148A14;\">\/\/ Property 'spfjgerijghoied' does not exist on type 'T'.<\/span>\r\n<span class=\"pl-kos\">}<\/span><\/pre>\n<\/div>\n<h3><code>export *<\/code> is Always Retained<\/h3>\n<p>In previous TypeScript versions, declarations like <code>export * from \"foo\"<\/code> would be dropped in our JavaScript output if <code>foo<\/code> didn&#8217;t export any values. This sort of emit is problematic because it&#8217;s type-directed and can&#8217;t be emulated by Babel. TypeScript 3.9 will always emit these <code>export *<\/code> declarations. In practice, we don&#8217;t expect this to break much existing code, but bundlers may have a harder time tree-shaking the code.<\/p>\n<p>You can see the specific changes in <a href=\"https:\/\/github.com\/microsoft\/TypeScript\/pull\/37124\">the original pull request<\/a>.<\/p>\n<h3>Exports Now Use Getters for Live Bindings<\/h3>\n<p>When targeting module systems like CommonJS in ES5 and above, TypeScript will use get accessors to emulate live bindings so that changes to a variable in one module are witnessed in any exporting modules. This change is meant to make TypeScript&#8217;s emit more compliant with ECMAScript modules.<\/p>\n<p>For more details, see <a href=\"https:\/\/github.com\/microsoft\/TypeScript\/pull\/35967\">the PR that applies this change<\/a>.<\/p>\n<h3>Exports are Hoisted and Initially Assigned<\/h3>\n<p>TypeScript now hoists exported declarations to the top of the file when targeting module systems like CommonJS in ES5 and above. This change is meant to make TypeScript&#8217;s emit more compliant with ECMAScript modules. For example, code like<\/p>\n<div class=\"highlight highlight-source-ts\">\n<pre class=\"lang:default decode:true\" style=\"background-color: #f0f0f0;padding: 10px;border-radius: 10px;\"><span style=\"color: #0000ff;\">export<\/span> * <span style=\"color: #0000ff;\">from<\/span> <span style=\"color: #a31515;\">\"mod\"<\/span><span class=\"pl-kos\">;<\/span>\r\n<span style=\"color: #0000ff;\">export<\/span> <span style=\"color: #0000ff;\">const<\/span> <span class=\"pl-s1\">nameFromMod<\/span> <span class=\"pl-c1\">=<\/span> <span style=\"color: #09885A;\">0<\/span><span class=\"pl-kos\">;<\/span><\/pre>\n<\/div>\n<p>previously had output like<\/p>\n<div class=\"highlight highlight-source-ts\">\n<pre class=\"lang:default decode:true\" style=\"background-color: #f0f0f0;padding: 10px;border-radius: 10px;\"><span class=\"pl-en\">__exportStar<\/span><span class=\"pl-kos\">(<\/span><span class=\"pl-s1\">exports<\/span><span class=\"pl-kos\">,<\/span> <span class=\"pl-en\">require<\/span><span class=\"pl-kos\">(<\/span><span style=\"color: #a31515;\">\"mod\"<\/span><span class=\"pl-kos\">)<\/span><span class=\"pl-kos\">)<\/span><span class=\"pl-kos\">;<\/span>\r\n<span class=\"pl-s1\">exports<\/span><span class=\"pl-kos\">.<\/span><span class=\"pl-c1\">nameFromMod<\/span> <span class=\"pl-c1\">=<\/span> <span style=\"color: #09885A;\">0<\/span><span class=\"pl-kos\">;<\/span><\/pre>\n<\/div>\n<p>However, because exports now use <code>get<\/code>-accessors, this assignment would throw because <code>__exportStar<\/code> now makes get-accesors which can&#8217;t be overridden with a simple assignment. Instead, TypeScript 3.9 emits the following:<\/p>\n<div class=\"highlight highlight-source-ts\">\n<pre class=\"lang:default decode:true\" style=\"background-color: #f0f0f0;padding: 10px;border-radius: 10px;\"><span class=\"pl-s1\">exports<\/span><span class=\"pl-kos\">.<\/span><span class=\"pl-c1\">nameFromMod<\/span> <span class=\"pl-c1\">=<\/span> <span style=\"color: #0000ff;\">void<\/span> <span style=\"color: #09885A;\">0<\/span><span class=\"pl-kos\">;<\/span>\r\n<span class=\"pl-en\">__exportStar<\/span><span class=\"pl-kos\">(<\/span><span class=\"pl-s1\">exports<\/span><span class=\"pl-kos\">,<\/span> <span class=\"pl-en\">require<\/span><span class=\"pl-kos\">(<\/span><span style=\"color: #a31515;\">\"mod\"<\/span><span class=\"pl-kos\">)<\/span><span class=\"pl-kos\">)<\/span><span class=\"pl-kos\">;<\/span>\r\n<span class=\"pl-s1\">exports<\/span><span class=\"pl-kos\">.<\/span><span class=\"pl-c1\">nameFromMod<\/span> <span class=\"pl-c1\">=<\/span> <span style=\"color: #09885A;\">0<\/span><span class=\"pl-kos\">;<\/span><\/pre>\n<\/div>\n<p>See <a href=\"https:\/\/github.com\/microsoft\/TypeScript\/pull\/37093\">the original pull request<\/a> for more information.<\/p>\n<h2>What&#8217;s Next?<\/h2>\n<p>We hope that TypeScript 3.9 makes your day-to-day coding fun, fast, and an overall joy to use. To stay in the loop on our next version, you can track the <a href=\"https:\/\/github.com\/microsoft\/TypeScript\/issues\/38510\">4.0 Iteration Plan<\/a> and our <a href=\"https:\/\/github.com\/Microsoft\/TypeScript\/wiki\/Roadmap\">Feature Roadmap<\/a> as it comes together.<\/p>\n<p>Happy hacking!<\/p>\n<p>&#8211; Daniel Rosenwasser and the TypeScript Team<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Today we&#8217;re excited to announce the release of TypeScript 3.9! If you&#8217;re unfamiliar with TypeScript, it&#8217;s a language that builds on JavaScript by adding syntax for type declarations and annotations. This syntax can be used by the TypeScript compiler to type-check our code, and then output clean readable JavaScript that runs on lots of different [&hellip;]<\/p>\n","protected":false},"author":381,"featured_media":1797,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[],"class_list":["post-2583","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-typescript"],"acf":[],"blog_post_summary":"<p>Today we&#8217;re excited to announce the release of TypeScript 3.9! If you&#8217;re unfamiliar with TypeScript, it&#8217;s a language that builds on JavaScript by adding syntax for type declarations and annotations. This syntax can be used by the TypeScript compiler to type-check our code, and then output clean readable JavaScript that runs on lots of different [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/typescript\/wp-json\/wp\/v2\/posts\/2583","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/typescript\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/typescript\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/typescript\/wp-json\/wp\/v2\/users\/381"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/typescript\/wp-json\/wp\/v2\/comments?post=2583"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/typescript\/wp-json\/wp\/v2\/posts\/2583\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/typescript\/wp-json\/wp\/v2\/media\/1797"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/typescript\/wp-json\/wp\/v2\/media?parent=2583"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/typescript\/wp-json\/wp\/v2\/categories?post=2583"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/typescript\/wp-json\/wp\/v2\/tags?post=2583"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}