{"id":2290,"date":"2019-08-16T09:48:17","date_gmt":"2019-08-16T17:48:17","guid":{"rendered":"https:\/\/devblogs.microsoft.com\/typescript\/?p=2290"},"modified":"2019-08-16T09:54:13","modified_gmt":"2019-08-16T17:54:13","slug":"announcing-typescript-3-6-rc","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/typescript\/announcing-typescript-3-6-rc\/","title":{"rendered":"Announcing TypeScript 3.6 RC"},"content":{"rendered":"<p>Today we&#8217;re happy to announce the availability of the release candidate of TypeScript 3.6. This release candidate is intended to be fairly close to the full release, and will stabilize for the next few weeks leading up to our official release.<\/p>\n<p>To get started using the RC, you can 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 -g typescript@rc<\/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-36rc\" rel=\"nofollow\">Downloading for Visual Studio 2019\/2017<\/a><\/li>\n<li>Following directions for <a href=\"https:\/\/code.visualstudio.com\/Docs\/languages\/typescript#_using-newer-typescript-versions\" rel=\"nofollow\">Visual Studio Code<\/a> and <a href=\"https:\/\/github.com\/Microsoft\/TypeScript-Sublime-Plugin\/#note-using-different-versions-of-typescript\">Sublime Text<\/a>.<\/li>\n<\/ul>\n<p>Let&#8217;s explore what&#8217;s coming in 3.6!<\/p>\n<h2>Stricter Generators<\/h2>\n<p>TypeScript 3.6 introduces stricter checking for iterators and generator functions. In earlier versions, users of generators had no way to differentiate whether a value was yielded or returned from a generator.<\/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-k\">*<\/span> foo() {\r\n    <span style=\"color: #0000ff;\">if<\/span> (<span class=\"pl-c1\">Math<\/span>.<span class=\"pl-c1\">random<\/span>() <span class=\"pl-k\">&lt;<\/span> <span style=\"color: #09885A;\">0.5<\/span>) <span style=\"color: #0000ff;\">yield<\/span> <span style=\"color: #09885A;\">100<\/span>;\r\n    <span style=\"color: #0000ff;\">return<\/span> <span style=\"color: #a31515;\"><span class=\"pl-pds\">\"<\/span>Finished!<span class=\"pl-pds\">\"<\/span><\/span>\r\n}\r\n\r\n<span style=\"color: #0000ff;\">let<\/span> iter <span class=\"pl-k\">=<\/span> <span class=\"pl-en\">foo<\/span>();\r\n<span style=\"color: #0000ff;\">let<\/span> curr <span class=\"pl-k\">=<\/span> <span class=\"pl-smi\">iter<\/span>.<span class=\"pl-en\">next<\/span>();\r\n<span style=\"color: #0000ff;\">if<\/span> (<span class=\"pl-smi\">curr<\/span>.<span class=\"pl-smi\">done<\/span>) {\r\n    <span style=\"color: #148A14;\">\/\/ TypeScript 3.5 and prior thought this was a 'string | number'.<\/span>\r\n    <span style=\"color: #148A14;\">\/\/ It should know it's 'string' since 'done' was 'true'!<\/span>\r\n    <span class=\"pl-smi\">curr<\/span>.<span class=\"pl-c1\">value<\/span>\r\n}<\/pre>\n<\/div>\n<p>Additionally, generators just assumed the type of <code>yield<\/code> was always <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-k\">*<\/span> bar() {\r\n    <span style=\"color: #0000ff;\">let<\/span> x<span class=\"pl-k\">:<\/span> { hello()<span class=\"pl-k\">:<\/span> <span class=\"pl-c1\">void<\/span> } <span class=\"pl-k\">=<\/span> <span style=\"color: #0000ff;\">yield<\/span>;\r\n    <span class=\"pl-smi\">x<\/span>.<span class=\"pl-en\">hello<\/span>();\r\n}\r\n\r\n<span style=\"color: #0000ff;\">let<\/span> iter <span class=\"pl-k\">=<\/span> <span class=\"pl-en\">bar<\/span>();\r\n<span class=\"pl-smi\">iter<\/span>.<span class=\"pl-en\">next<\/span>();\r\n<span class=\"pl-smi\">iter<\/span>.<span class=\"pl-en\">next<\/span>(<span style=\"color: #09885A;\">123<\/span>); <span style=\"color: #148A14;\">\/\/ oops! runtime error!<\/span><\/pre>\n<\/div>\n<p>In TypeScript 3.6, the checker now knows that the correct type for <code>curr.value<\/code> should be <code>string<\/code> in our first example, and will correctly error on our call to <code>next()<\/code> in our last example. This is thanks to some changes in the <code>Iterator<\/code> and <code>IteratorResult<\/code> type declarations to include a few new type parameters, and to a new type that TypeScript uses to represent generators called the <code>Generator<\/code> type.<\/p>\n<p>The <code>Iterator<\/code> type now allows users to specify the yielded type, the returned type, and the type that <code>next<\/code> can accept.<\/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;\">Iterator<\/span>&lt;<span style=\"color: #267F99;\">T<\/span>, <span style=\"color: #267F99;\">TReturn<\/span> <span class=\"pl-k\">=<\/span> <span style=\"color: #0000ff;\">any<\/span>, <span style=\"color: #267F99;\">TNext<\/span> <span class=\"pl-k\">=<\/span> <span style=\"color: #0000ff;\">undefined<\/span>&gt; {\r\n    <span style=\"color: #148A14;\">\/\/ Takes either 0 or 1 arguments - doesn't accept 'undefined'<\/span>\r\n    next(<span class=\"pl-k\">...<\/span><span class=\"pl-v\">args<\/span><span class=\"pl-k\">:<\/span> [] <span class=\"pl-k\">|<\/span> [<span style=\"color: #267F99;\">TNext<\/span>])<span class=\"pl-k\">:<\/span> <span style=\"color: #267F99;\">IteratorResult<\/span>&lt;<span style=\"color: #267F99;\">T<\/span>, <span style=\"color: #267F99;\">TReturn<\/span>&gt;;\r\n    return<span class=\"pl-k\">?<\/span>(<span class=\"pl-v\">value<\/span><span class=\"pl-k\">?<\/span><span class=\"pl-k\">:<\/span> <span style=\"color: #267F99;\">TReturn<\/span>)<span class=\"pl-k\">:<\/span> <span style=\"color: #267F99;\">IteratorResult<\/span>&lt;<span style=\"color: #267F99;\">T<\/span>, <span style=\"color: #267F99;\">TReturn<\/span>&gt;;\r\n    throw<span class=\"pl-k\">?<\/span>(<span class=\"pl-v\">e<\/span><span class=\"pl-k\">?<\/span><span class=\"pl-k\">:<\/span> <span style=\"color: #0000ff;\">any<\/span>)<span class=\"pl-k\">:<\/span> <span style=\"color: #267F99;\">IteratorResult<\/span>&lt;<span style=\"color: #267F99;\">T<\/span>, <span style=\"color: #267F99;\">TReturn<\/span>&gt;;\r\n}<\/pre>\n<\/div>\n<p>Building on that work, the new <code>Generator<\/code> type is an <code>Iterator<\/code> that always has both the <code>return<\/code> and <code>throw<\/code> methods present, and is also iterable.<\/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;\">Generator<\/span>&lt;<span style=\"color: #267F99;\">T<\/span> <span class=\"pl-k\">=<\/span> <span style=\"color: #0000ff;\">unknown<\/span>, <span style=\"color: #267F99;\">TReturn<\/span> <span class=\"pl-k\">=<\/span> <span style=\"color: #0000ff;\">any<\/span>, <span style=\"color: #267F99;\">TNext<\/span> <span class=\"pl-k\">=<\/span> <span style=\"color: #0000ff;\">unknown<\/span>&gt;\r\n        <span style=\"color: #0000ff;\">extends<\/span> <span style=\"color: #267F99;\">Iterator<\/span>&lt;<span style=\"color: #267F99;\">T<\/span>, <span style=\"color: #267F99;\">TReturn<\/span>, <span style=\"color: #267F99;\">TNext<\/span>&gt; {\r\n    next(<span class=\"pl-k\">...<\/span><span class=\"pl-v\">args<\/span><span class=\"pl-k\">:<\/span> [] <span class=\"pl-k\">|<\/span> [<span style=\"color: #267F99;\">TNext<\/span>])<span class=\"pl-k\">:<\/span> <span style=\"color: #267F99;\">IteratorResult<\/span>&lt;<span style=\"color: #267F99;\">T<\/span>, <span style=\"color: #267F99;\">TReturn<\/span>&gt;;\r\n    return(<span class=\"pl-v\">value<\/span><span class=\"pl-k\">:<\/span> <span style=\"color: #267F99;\">TReturn<\/span>)<span class=\"pl-k\">:<\/span> <span style=\"color: #267F99;\">IteratorResult<\/span>&lt;<span style=\"color: #267F99;\">T<\/span>, <span style=\"color: #267F99;\">TReturn<\/span>&gt;;\r\n    throw(<span class=\"pl-v\">e<\/span><span class=\"pl-k\">:<\/span> <span style=\"color: #0000ff;\">any<\/span>)<span class=\"pl-k\">:<\/span> <span style=\"color: #267F99;\">IteratorResult<\/span>&lt;<span style=\"color: #267F99;\">T<\/span>, <span style=\"color: #267F99;\">TReturn<\/span>&gt;;\r\n    [<span class=\"pl-c1\">Symbol<\/span>.<span class=\"pl-smi\">iterator<\/span>]()<span class=\"pl-k\">:<\/span> <span style=\"color: #267F99;\">Generator<\/span>&lt;<span style=\"color: #267F99;\">T<\/span>, <span style=\"color: #267F99;\">TReturn<\/span>, <span style=\"color: #267F99;\">TNext<\/span>&gt;;\r\n}<\/pre>\n<\/div>\n<p>To allow differentiation between returned values and yielded values, TypeScript 3.6 converts the <code>IteratorResult<\/code> type to a discriminated union type:<\/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;\">type<\/span> <span style=\"color: #267F99;\">IteratorResult<\/span>&lt;<span style=\"color: #267F99;\">T<\/span>, <span style=\"color: #267F99;\">TReturn<\/span> <span class=\"pl-k\">=<\/span> <span style=\"color: #0000ff;\">any<\/span>&gt; <span class=\"pl-k\">=<\/span> <span style=\"color: #267F99;\">IteratorYieldResult<\/span>&lt;<span style=\"color: #267F99;\">T<\/span>&gt; <span class=\"pl-k\">|<\/span> <span style=\"color: #267F99;\">IteratorReturnResult<\/span>&lt;<span style=\"color: #267F99;\">TReturn<\/span>&gt;;\r\n\r\n<span style=\"color: #0000ff;\">interface<\/span> <span style=\"color: #267F99;\">IteratorYieldResult<\/span>&lt;<span style=\"color: #267F99;\">TYield<\/span>&gt; {\r\n    done<span class=\"pl-k\">?<\/span><span class=\"pl-k\">:<\/span> <span style=\"color: #0000ff;\">false<\/span>;\r\n    value<span class=\"pl-k\">:<\/span> <span style=\"color: #267F99;\">TYield<\/span>;\r\n}\r\n\r\n<span style=\"color: #0000ff;\">interface<\/span> <span style=\"color: #267F99;\">IteratorReturnResult<\/span>&lt;<span style=\"color: #267F99;\">TReturn<\/span>&gt; {\r\n    done<span class=\"pl-k\">:<\/span> <span style=\"color: #0000ff;\">true<\/span>;\r\n    value<span class=\"pl-k\">:<\/span> <span style=\"color: #267F99;\">TReturn<\/span>;\r\n}<\/pre>\n<\/div>\n<p>In short, what this means is that you&#8217;ll be able to appropriately narrow down values from iterators when dealing with them directly.<\/p>\n<p>To correctly represent the types that can be passed in to a generator from calls to <code>next()<\/code>, TypeScript 3.6 also infers certain uses of <code>yield<\/code> within the body of a generator 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-k\">*<\/span> foo() {\r\n    <span style=\"color: #0000ff;\">let<\/span> x<span class=\"pl-k\">:<\/span> <span style=\"color: #0000ff;\">string<\/span> <span class=\"pl-k\">=<\/span> <span style=\"color: #0000ff;\">yield<\/span>;\r\n    <span class=\"pl-c1\">console<\/span>.<span class=\"pl-c1\">log<\/span>(<span class=\"pl-smi\">x<\/span>.<span class=\"pl-c1\">toUpperCase<\/span>());\r\n}\r\n\r\n<span style=\"color: #0000ff;\">let<\/span> x <span class=\"pl-k\">=<\/span> <span class=\"pl-en\">foo<\/span>();\r\n<span class=\"pl-smi\">x<\/span>.<span class=\"pl-en\">next<\/span>(); <span style=\"color: #148A14;\">\/\/ first call to 'next' is always ignored<\/span>\r\n<span class=\"pl-smi\">x<\/span>.<span class=\"pl-en\">next<\/span>(<span style=\"color: #09885A;\">42<\/span>); <span style=\"color: #148A14;\">\/\/ error! 'number' is not assignable to 'string'<\/span><\/pre>\n<\/div>\n<p>If you&#8217;d prefer to be explicit, you can also enforce the type of values that can be returned, yielded, and evaluated from <code>yield<\/code> expressions using an explicit return type. Below, <code>next()<\/code> can only be called with <code>boolean<\/code>s, and depending on the value of <code>done<\/code>, <code>value<\/code> is either a <code>string<\/code> or a <code>number<\/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>\r\n<span style=\"color: #148A14;\"> * - yields numbers<\/span>\r\n<span style=\"color: #148A14;\"> * - returns strings<\/span>\r\n<span style=\"color: #148A14;\"> * - can be passed in booleans<\/span>\r\n<span style=\"color: #148A14;\"> *\/<\/span>\r\n<span style=\"color: #0000ff;\">function<\/span><span class=\"pl-k\">*<\/span> counter()<span class=\"pl-k\">:<\/span> <span style=\"color: #267F99;\">Generator<\/span>&lt;<span style=\"color: #0000ff;\">number<\/span>, <span style=\"color: #0000ff;\">string<\/span>, <span style=\"color: #0000ff;\">boolean<\/span>&gt; {\r\n    <span style=\"color: #0000ff;\">let<\/span> i <span class=\"pl-k\">=<\/span> <span style=\"color: #09885A;\">0<\/span>;\r\n    <span style=\"color: #0000ff;\">while<\/span> (<span style=\"color: #0000ff;\">true<\/span>) {\r\n        <span style=\"color: #0000ff;\">if<\/span> (<span style=\"color: #0000ff;\">yield<\/span> <span class=\"pl-smi\">i<\/span><span class=\"pl-k\">++<\/span>) {\r\n            <span style=\"color: #0000ff;\">break<\/span>;\r\n        }\r\n    }\r\n    <span style=\"color: #0000ff;\">return<\/span> <span style=\"color: #a31515;\"><span class=\"pl-pds\">\"<\/span>done!<span class=\"pl-pds\">\"<\/span><\/span>;\r\n}\r\n\r\n<span style=\"color: #0000ff;\">var<\/span> iter <span class=\"pl-k\">=<\/span> <span class=\"pl-en\">counter<\/span>();\r\n<span style=\"color: #0000ff;\">var<\/span> curr <span class=\"pl-k\">=<\/span> <span class=\"pl-smi\">iter<\/span>.<span class=\"pl-en\">next<\/span>()\r\n<span style=\"color: #0000ff;\">while<\/span> (<span class=\"pl-k\">!<\/span><span class=\"pl-smi\">curr<\/span>.<span class=\"pl-smi\">done<\/span>) {\r\n    <span class=\"pl-c1\">console<\/span>.<span class=\"pl-c1\">log<\/span>(<span class=\"pl-smi\">curr<\/span>.<span class=\"pl-c1\">value<\/span>);\r\n    <span class=\"pl-smi\">curr<\/span> <span class=\"pl-k\">=<\/span> <span class=\"pl-smi\">iter<\/span>.<span class=\"pl-en\">next<\/span>(<span class=\"pl-smi\">curr<\/span>.<span class=\"pl-c1\">value<\/span> <span class=\"pl-k\">===<\/span> <span style=\"color: #09885A;\">5<\/span>)\r\n}\r\n<span class=\"pl-c1\">console<\/span>.<span class=\"pl-c1\">log<\/span>(<span class=\"pl-smi\">curr<\/span>.<span class=\"pl-c1\">value<\/span>.<span class=\"pl-c1\">toUpperCase<\/span>());\r\n\r\n<span style=\"color: #148A14;\">\/\/ prints:<\/span>\r\n<span style=\"color: #148A14;\">\/\/<\/span>\r\n<span style=\"color: #148A14;\">\/\/ 0<\/span>\r\n<span style=\"color: #148A14;\">\/\/ 1<\/span>\r\n<span style=\"color: #148A14;\">\/\/ 2<\/span>\r\n<span style=\"color: #148A14;\">\/\/ 3<\/span>\r\n<span style=\"color: #148A14;\">\/\/ 4<\/span>\r\n<span style=\"color: #148A14;\">\/\/ 5<\/span>\r\n<span style=\"color: #148A14;\">\/\/ DONE!<\/span><\/pre>\n<\/div>\n<p>For more details on the change, <a href=\"https:\/\/github.com\/Microsoft\/TypeScript\/issues\/2983\">see the pull request here<\/a>.<\/p>\n<h2>More Accurate Array Spread<\/h2>\n<p>In pre-ES2015 targets, the most faithful emit for constructs like <code>for<\/code>\/<code>of<\/code> loops and array spreads can be a bit heavy. For this reason, TypeScript uses a simpler emit by default that only supports array types, and supports iterating on other types using the <code>--downlevelIteration<\/code> flag. Under this flag, the emitted code is more accurate, but is much larger.<\/p>\n<p><code>--downlevelIteration<\/code> being off by default works well since, by-and-large, most users targeting ES5 only plan to use iterative constructs with arrays. However, our emit that only supported arrays still had some observable differences in some edge cases.<\/p>\n<p>For example, the following 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 class=\"pl-k\">...<\/span><span class=\"pl-c1\">Array<\/span>(<span style=\"color: #09885A;\">5<\/span>)]<\/pre>\n<\/div>\n<p>is equivalent to the following array.<\/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;\">undefined<\/span>, <span style=\"color: #0000ff;\">undefined<\/span>, <span style=\"color: #0000ff;\">undefined<\/span>, <span style=\"color: #0000ff;\">undefined<\/span>, <span style=\"color: #0000ff;\">undefined<\/span>]<\/pre>\n<\/div>\n<p>However, TypeScript would instead transform the original code into this 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-c1\">Array<\/span>(<span style=\"color: #09885A;\">5<\/span>).<span class=\"pl-c1\">slice<\/span>();<\/pre>\n<\/div>\n<p>This is slightly different. <code>Array(5)<\/code> produces an array with a length of 5, but with no defined property slots!<\/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: #09885A;\">1<\/span> <span style=\"color: #0000ff;\">in<\/span> [<span style=\"color: #0000ff;\">undefined<\/span>, <span style=\"color: #0000ff;\">undefined<\/span>, <span style=\"color: #0000ff;\">undefined<\/span>] <span style=\"color: #148A14;\">\/\/ true<\/span>\r\n<span style=\"color: #09885A;\">1<\/span> <span style=\"color: #0000ff;\">in<\/span> <span class=\"pl-c1\">Array<\/span>(<span style=\"color: #09885A;\">3<\/span>) <span style=\"color: #148A14;\">\/\/ false<\/span><\/pre>\n<\/div>\n<p>And when TypeScript calls <code>slice()<\/code>, it <em>also<\/em> creates an array with indices that haven&#8217;t been set.<\/p>\n<p>This might seem a bit of an esoteric difference, but it turns out many users were running into this undesirable behavior. Instead of using <code>slice()<\/code> and built-ins, TypeScript 3.6 introduces a new <code>__spreadArrays<\/code> helper to accurately model what happens in ECMAScript 2015 in older targets outside of <code>--downlevelIteration<\/code>. <code>__spreadArrays<\/code> is also available in <a href=\"https:\/\/github.com\/Microsoft\/tslib\/\">tslib<\/a> (which is worth checking out if you&#8217;re looking for smaller bundle sizes).<\/p>\n<p>For more information, <a href=\"https:\/\/github.com\/microsoft\/TypeScript\/pull\/31166\">see the relevant pull request<\/a>.<\/p>\n<h2>Improved UX Around Promises<\/h2>\n<p><code>Promise<\/code>s are one of the most common ways to work with asynchronous data nowadays. Unfortunately, using a <code>Promise<\/code>-oriented API can often be confusing for users. TypeScript 3.6 introduces some improvements for when <code>Promise<\/code>s are mis-handled.<\/p>\n<p>For example, it&#8217;s often very common to forget to <code>.then()<\/code> or <code>await<\/code> the contents of a <code>Promise<\/code> before passing it to another function. TypeScript&#8217;s error messages are now specialized, and inform the user that perhaps they should consider using the <code>await<\/code> keyword.<\/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;\">User<\/span> {\r\n    name<span class=\"pl-k\">:<\/span> <span style=\"color: #0000ff;\">string<\/span>;\r\n    age<span class=\"pl-k\">:<\/span> <span style=\"color: #0000ff;\">number<\/span>;\r\n    location<span class=\"pl-k\">:<\/span> <span style=\"color: #0000ff;\">string<\/span>;\r\n}\r\n\r\n<span style=\"color: #0000ff;\">declare<\/span> <span style=\"color: #0000ff;\">function<\/span> getUserData()<span class=\"pl-k\">:<\/span> <span style=\"color: #267F99;\">Promise<\/span>&lt;<span style=\"color: #267F99;\">User<\/span>&gt;;\r\n<span style=\"color: #0000ff;\">declare<\/span> <span style=\"color: #0000ff;\">function<\/span> displayUser(<span class=\"pl-v\">user<\/span><span class=\"pl-k\">:<\/span> <span style=\"color: #267F99;\">User<\/span>)<span class=\"pl-k\">:<\/span> <span class=\"pl-c1\">void<\/span>;\r\n\r\n<span style=\"color: #0000ff;\">async<\/span> <span style=\"color: #0000ff;\">function<\/span> f() {\r\n    <span class=\"pl-en\">displayUser<\/span>(<span class=\"pl-en\">getUserData<\/span>());\r\n<span style=\"color: #148A14;\">\/\/              ~~~~~~~~~~~~~<\/span>\r\n<span style=\"color: #148A14;\">\/\/ Argument of type 'Promise&lt;User&gt;' is not assignable to parameter of type 'User'.<\/span>\r\n<span style=\"color: #148A14;\">\/\/   ...<\/span>\r\n<span style=\"color: #148A14;\">\/\/ Did you forget to use 'await'?<\/span>\r\n}<\/pre>\n<\/div>\n<p>It&#8217;s also common to try to access a method before <code>await<\/code>-ing or <code>.then()<\/code>-ing a <code>Promise<\/code>. This is another example, among many others, where we&#8217;re able to do better.<\/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;\">async<\/span> <span style=\"color: #0000ff;\">function<\/span> getCuteAnimals() {\r\n    <span class=\"pl-en\">fetch<\/span>(<span style=\"color: #a31515;\"><span class=\"pl-pds\">\"<\/span>https:\/\/reddit.com\/r\/aww.json<span class=\"pl-pds\">\"<\/span><\/span>)\r\n        .<span class=\"pl-en\">json<\/span>()\r\n    <span style=\"color: #148A14;\">\/\/   ~~~~<\/span>\r\n    <span style=\"color: #148A14;\">\/\/ Property 'json' does not exist on type 'Promise&lt;Response&gt;'.<\/span>\r\n    <span style=\"color: #148A14;\">\/\/<\/span>\r\n    <span style=\"color: #148A14;\">\/\/ Did you forget to use 'await'?<\/span>\r\n}<\/pre>\n<\/div>\n<p>The intent is that even if a user is not aware of <code>await<\/code>, at the very least, these messages provide some more context on where to go from here.<\/p>\n<p>In the same vein of discoverability and making your life easier &#8211; apart from better error messages on <code>Promise<\/code>s, we now also provide quick fixes in some cases as well.<\/p>\n<p><a href=\"https:\/\/user-images.githubusercontent.com\/3277153\/61071690-8ca53480-a3c6-11e9-9b08-4e6d9851c9db.gif\" target=\"_blank\" rel=\"noopener noreferrer\"><img decoding=\"async\" src=\"https:\/\/user-images.githubusercontent.com\/3277153\/61071690-8ca53480-a3c6-11e9-9b08-4e6d9851c9db.gif\" alt=\"Quick fixes being applied to add missing 'await' keywords.\" \/><\/a><\/p>\n<p>For more details, <a href=\"https:\/\/github.com\/microsoft\/TypeScript\/issues\/30646\">see the originating issue<\/a>, as well as the pull requests that link back to it.<\/p>\n<h2>Better Unicode Support for Identifiers<\/h2>\n<p>TypeScript 3.6 contains better support for Unicode characters in identifiers when emitting to ES2015 and later targets.<\/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> \ud835\udcf1\ud835\udcee\ud835\udcf5\ud835\udcf5\ud835\udcf8 <span class=\"pl-k\">=<\/span> <span style=\"color: #a31515;\"><span class=\"pl-pds\">\"<\/span>world<span class=\"pl-pds\">\"<\/span><\/span>; <span style=\"color: #148A14;\">\/\/ previously disallowed, now allowed in '--target es2015'<\/span><\/pre>\n<\/div>\n<h2><code style=\"color: #a31515; font-size: 29px;\">import.meta<\/code> Support in SystemJS<\/h2>\n<p>TypeScript 3.6 supports transforming <code>import.meta<\/code> to <code>context.meta<\/code> in when your <code>module<\/code> target is set to <code>system<\/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;\">\/\/ This module:<\/span>\r\n\r\n<span class=\"pl-c1\">console<\/span>.<span class=\"pl-c1\">log<\/span>(<span style=\"color: #0000ff;\">import<\/span>.<span class=\"pl-c1\">meta<\/span>.<span class=\"pl-smi\">url<\/span>)\r\n\r\n<span style=\"color: #148A14;\">\/\/ gets turned into the following:<\/span>\r\n\r\n<span class=\"pl-smi\">System<\/span>.<span class=\"pl-en\">register<\/span>([], <span style=\"color: #0000ff;\">function<\/span> (<span class=\"pl-v\">exports<\/span>, <span class=\"pl-v\">context<\/span>) {\r\n  <span style=\"color: #0000ff;\">return<\/span> {\r\n    setters: [],\r\n    <span class=\"pl-en\">execute<\/span>: <span style=\"color: #0000ff;\">function<\/span> () {\r\n      <span class=\"pl-c1\">console<\/span>.<span class=\"pl-c1\">log<\/span>(<span class=\"pl-smi\">context<\/span>.<span class=\"pl-smi\">meta<\/span>.<span class=\"pl-smi\">url<\/span>);\r\n    }\r\n  };\r\n});<\/pre>\n<\/div>\n<h2><code style=\"color: #a31515; font-size: 29px;\">get<\/code> and <code style=\"color: #a31515; font-size: 29px;\">set<\/code> Accessors Are Allowed in Ambient Contexts<\/h2>\n<p>In previous versions of TypeScript, the language didn&#8217;t allow <code>get<\/code> and <code>set<\/code> accessors in ambient contexts (like in <code>declare<\/code>-d classes, or in <code>.d.ts<\/code> files in general). The rationale was that accessors weren&#8217;t distinct from properties as far as writing and reading to these properties; however, <a href=\"https:\/\/github.com\/tc39\/proposal-class-fields\/issues\/248\">because ECMAScript&#8217;s class fields proposal may have differing behavior from in existing versions of TypeScript<\/a>, we realized we needed a way to communicate this different behavior to provide appropriate errors in subclasses.<\/p>\n<p>As a result, users can write getters and setters in ambient contexts in TypeScript 3.6.<\/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;\">class<\/span> <span style=\"color: #267F99;\">Foo<\/span> {\r\n    <span style=\"color: #148A14;\">\/\/ Allowed in 3.6+.<\/span>\r\n    <span style=\"color: #0000ff;\">get<\/span> x()<span class=\"pl-k\">:<\/span> <span style=\"color: #0000ff;\">number<\/span>;\r\n    <span style=\"color: #0000ff;\">set<\/span> x(<span class=\"pl-v\">val<\/span><span class=\"pl-k\">:<\/span> <span style=\"color: #0000ff;\">number<\/span>)<span class=\"pl-k\">:<\/span> <span class=\"pl-c1\">void<\/span>;\r\n}<\/pre>\n<\/div>\n<p>In TypeScript 3.7, the compiler itself will take advantage of this feature so that generated <code>.d.ts<\/code> files will also emit <code>get<\/code>\/<code>set<\/code> accessors.<\/p>\n<h2>Ambient Classes and Functions Can Merge<\/h2>\n<p>In previous versions of TypeScript, it was an error to merge classes and functions under any circumstances. Now, ambient classes and functions (classes\/functions with the <code>declare<\/code> modifier, or in <code>.d.ts<\/code> files) can merge. This means that now you can write 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;\">export<\/span> <span style=\"color: #0000ff;\">declare<\/span> <span style=\"color: #0000ff;\">function<\/span> Point2D(<span class=\"pl-v\">x<\/span><span class=\"pl-k\">:<\/span> <span style=\"color: #0000ff;\">number<\/span>, <span class=\"pl-v\">y<\/span><span class=\"pl-k\">:<\/span> <span style=\"color: #0000ff;\">number<\/span>)<span class=\"pl-k\">:<\/span> <span style=\"color: #267F99;\">Point2D<\/span>;\r\n<span style=\"color: #0000ff;\">export<\/span> <span style=\"color: #0000ff;\">declare<\/span> <span style=\"color: #0000ff;\">class<\/span> <span style=\"color: #267F99;\">Point2D<\/span> {\r\n    x<span class=\"pl-k\">:<\/span> <span style=\"color: #0000ff;\">number<\/span>;\r\n    y<span class=\"pl-k\">:<\/span> <span style=\"color: #0000ff;\">number<\/span>;\r\n    <span style=\"color: #0000ff;\">constructor<\/span>(<span class=\"pl-v\">x<\/span><span class=\"pl-k\">:<\/span> <span style=\"color: #0000ff;\">number<\/span>, <span class=\"pl-v\">y<\/span><span class=\"pl-k\">:<\/span> <span style=\"color: #0000ff;\">number<\/span>);\r\n}<\/pre>\n<\/div>\n<p>instead of needing to use<\/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;\">interface<\/span> <span style=\"color: #267F99;\">Point2D<\/span> {\r\n    x<span class=\"pl-k\">:<\/span> <span style=\"color: #0000ff;\">number<\/span>;\r\n    y<span class=\"pl-k\">:<\/span> <span style=\"color: #0000ff;\">number<\/span>;\r\n}\r\n<span style=\"color: #0000ff;\">export<\/span> <span style=\"color: #0000ff;\">declare<\/span> <span style=\"color: #0000ff;\">var<\/span> Point2D<span class=\"pl-k\">:<\/span> {\r\n    (<span class=\"pl-v\">x<\/span><span class=\"pl-k\">:<\/span> <span style=\"color: #0000ff;\">number<\/span>, <span class=\"pl-v\">y<\/span><span class=\"pl-k\">:<\/span> <span style=\"color: #0000ff;\">number<\/span>)<span class=\"pl-k\">:<\/span> <span style=\"color: #267F99;\">Point2D<\/span>;\r\n    <span style=\"color: #0000ff;\">new<\/span> (<span class=\"pl-v\">x<\/span><span class=\"pl-k\">:<\/span> <span style=\"color: #0000ff;\">number<\/span>, <span class=\"pl-v\">y<\/span><span class=\"pl-k\">:<\/span> <span style=\"color: #0000ff;\">number<\/span>)<span class=\"pl-k\">:<\/span> <span style=\"color: #267F99;\">Point2D<\/span>;\r\n}<\/pre>\n<\/div>\n<p>One advantage of this is that the callable constructor pattern can be easily expressed while also allowing namespaces to merge with these declarations (since <code>var<\/code> declarations can&#8217;t merge with <code>namespace<\/code>s).<\/p>\n<p>In TypeScript 3.7, the compiler will take advantage of this feature so that <code>.d.ts<\/code> files generated from <code>.js<\/code> files can appropriately capture both the callability and constructability of a class-like function.<\/p>\n<p>For more details, <a href=\"https:\/\/github.com\/microsoft\/TypeScript\/pull\/32584\">see the original PR on GitHub<\/a>.<\/p>\n<h2>APIs to Support <code style=\"color: #a31515; font-size: 29px;\">--build<\/code> and <code style=\"color: #a31515; font-size: 29px;\">--incremental<\/code><\/h2>\n<p>TypeScript 3.0 introduced support for referencing other and building them incrementally using the <code>--build<\/code> flag. Additionally, TypeScript 3.4 introduced the <code>--incremental<\/code> flag for saving information about previous compilations to only rebuild certain files. These flags were incredibly useful for structuring projects more flexibly and speeding builds up. Unfortunately, using these flags didn&#8217;t work with 3rd party build tools like Gulp and Webpack. TypeScript 3.6 now exposes two sets of APIs to operate on project references and incremental program building.<\/p>\n<p>For creating <code>--incremental<\/code> builds, users can leverage the <code>createIncrementalProgram<\/code> and <code>createIncrementalCompilerHost<\/code> APIs. Users can also re-hydrate old program instances from <code>.tsbuildinfo<\/code> files generated by this API using the newly exposed <code>readBuilderProgram<\/code> function, which is only meant to be used as for creating new programs (i.e. you can&#8217;t modify the returned instance &#8211; it&#8217;s only meant to be used for the <code>oldProgram<\/code> parameter in other <code>create*Program<\/code> functions).<\/p>\n<p>For leveraging project references, a new <code>createSolutionBuilder<\/code> function has been exposed, which returns an instance of the new type <code>SolutionBuilder<\/code>.<\/p>\n<p>For more details on these APIs, you can <a href=\"https:\/\/github.com\/microsoft\/TypeScript\/pull\/31432\">see the original pull request<\/a>.<\/p>\n<h2>Semicolon-Aware Code Edits<\/h2>\n<p>Editors like Visual Studio and Visual Studio Code can automatically apply quick fixes, refactorings, and other transformations like automatically importing values from other modules. These transformations are powered by TypeScript, and older versions of TypeScript unconditionally added semicolons to the end of every statement; unfortunately, this disagreed with many users&#8217; style guidelines, and many users were displeased with the editor inserting semicolons.<\/p>\n<p>TypeScript is now smart enough to detect whether your file uses semicolons when applying these sorts of edits. If your file generally lacks semicolons, TypeScript won&#8217;t add one.<\/p>\n<p>For more details, <a href=\"https:\/\/github.com\/microsoft\/TypeScript\/pull\/31801\">see the corresponding pull request<\/a>.<\/p>\n<h2>Smarter Auto-Import Syntax<\/h2>\n<p>JavaScript has a lot of different module syntaxes or conventions: the one in the ECMAScript standard, the one Node already supports (CommonJS), AMD, System.js, and more! For the most part, TypeScript would default to auto-importing using ECMAScript module syntax, which was often inappropriate in certain TypeScript projects with different compiler settings, or in Node projects with plain JavaScript and <code>require<\/code> calls.<\/p>\n<p>TypeScript 3.6 is now a bit smarter about looking at your existing imports before deciding on how to auto-import other modules. You can <a href=\"https:\/\/github.com\/microsoft\/TypeScript\/pull\/32684\">see more details in the original pull request here<\/a>.<\/p>\n<h2>Breaking Changes<\/h2>\n<h3>String-Named Methods Named <code style=\"color: #a31515; font-size: 26px;\">\"constructor\"<\/code> Are Constructors<\/h3>\n<p>As per the ECMAScript specification, class declarations with methods named <code>constructor<\/code> are now constructor functions, regardless of whether they are declared using identifier names, or string names.<\/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;\">class<\/span> <span style=\"color: #267F99;\">C<\/span> {\r\n    <span style=\"color: #a31515;\"><span class=\"pl-pds\">\"<\/span>constructor<span class=\"pl-pds\">\"<\/span><\/span>() {\r\n        <span class=\"pl-c1\">console<\/span>.<span class=\"pl-c1\">log<\/span>(<span style=\"color: #a31515;\"><span class=\"pl-pds\">\"<\/span>I am the constructor now.<span class=\"pl-pds\">\"<\/span><\/span>);\r\n    }\r\n}<\/pre>\n<\/div>\n<p>A notable exception, and the workaround to this break, is using a computed property whose name evaluates to <code>\"constructor\"<\/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;\">class<\/span> <span style=\"color: #267F99;\">D<\/span> {\r\n    [<span style=\"color: #a31515;\"><span class=\"pl-pds\">\"<\/span>constructor<span class=\"pl-pds\">\"<\/span><\/span>]() {\r\n        <span class=\"pl-c1\">console<\/span>.<span class=\"pl-c1\">log<\/span>(<span style=\"color: #a31515;\"><span class=\"pl-pds\">\"<\/span>I'm not a constructor - just a plain method!<span class=\"pl-pds\">\"<\/span><\/span>);\r\n    }\r\n}<\/pre>\n<\/div>\n<h3>DOM Updates<\/h3>\n<p>Many declarations have been removed or changed within <code>lib.dom.d.ts<\/code>. This includes (but isn&#8217;t limited to) the following:<\/p>\n<ul>\n<li>The global <code>window<\/code> is no longer defined as type <code>Window<\/code> &#8211; instead, it is defined as type <code>Window &amp; typeof globalThis<\/code>. Instead use <code>typeof window<\/code>.<\/li>\n<li><code>GlobalFetch<\/code> is gone. Instead, use <code>WindowOrWorkerGlobalScope<\/code><\/li>\n<li>Certain non-standard properties on <code>Navigator<\/code> are gone.<\/li>\n<li>The <code>experimental-webgl<\/code> context is gone. Instead, use <code>webgl<\/code> or <code>webgl2<\/code>.<\/li>\n<\/ul>\n<p>If you believe a change has been made in error, <a href=\"https:\/\/github.com\/Microsoft\/TSJS-lib-generator\/\">please file an issue<\/a>!<\/p>\n<h3>JSDoc Comments Don&#8217;t Merge<\/h3>\n<p>In JavaScript files, TypeScript will only consult immediately preceding JSDoc comments to figure out declared types.<\/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>\r\n<span style=\"color: #148A14;\"> * <span class=\"pl-k\">@param<\/span> <span class=\"pl-en\">{string}<\/span> <span class=\"pl-smi\">arg<\/span><\/span>\r\n<span style=\"color: #148A14;\"> *\/<\/span>\r\n<span style=\"color: #148A14;\">\/**<\/span>\r\n<span style=\"color: #148A14;\"> * oh, hi, were you trying to type something?<\/span>\r\n<span style=\"color: #148A14;\"> *\/<\/span>\r\n<span style=\"color: #0000ff;\">function<\/span> whoWritesFunctionsLikeThis(<span class=\"pl-v\">arg<\/span>) {\r\n    <span style=\"color: #148A14;\">\/\/ 'arg' has type 'any'<\/span>\r\n}<\/pre>\n<\/div>\n<h3>Keywords Cannot Contain Escape Sequences<\/h3>\n<p>Previously keywords were not allowed to contain escape sequences. TypeScript 3.6 disallows them.<\/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;\">while<\/span> (<span style=\"color: #0000ff;\">true<\/span>) {\r\n    \\<span class=\"pl-smi\">u0063ontinue<\/span>;\r\n<span style=\"color: #148A14;\">\/\/  ~~~~~~~~~~~~~<\/span>\r\n<span style=\"color: #148A14;\">\/\/  error! Keywords cannot contain escape characters.<\/span>\r\n}<\/pre>\n<\/div>\n<h2>What&#8217;s Next?<\/h2>\n<p>TypeScript 3.6 is slated for the end of this month. We hope you give this release a shot and let us know how things work. If you have any suggestions or run into any problems, <a href=\"https:\/\/github.com\/microsoft\/TypeScript\/issues\/new\/choose\">don&#8217;t be afraid to drop by the issue tracker and open up an issue<\/a>!<\/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 happy to announce the availability of the release candidate of TypeScript 3.6. This release candidate is intended to be fairly close to the full release, and will stabilize for the next few weeks leading up to our official release. To get started using the RC, you can get it through NuGet, or use [&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-2290","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-typescript"],"acf":[],"blog_post_summary":"<p>Today we&#8217;re happy to announce the availability of the release candidate of TypeScript 3.6. This release candidate is intended to be fairly close to the full release, and will stabilize for the next few weeks leading up to our official release. To get started using the RC, you can get it through NuGet, or use [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/typescript\/wp-json\/wp\/v2\/posts\/2290","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=2290"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/typescript\/wp-json\/wp\/v2\/posts\/2290\/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=2290"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/typescript\/wp-json\/wp\/v2\/categories?post=2290"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/typescript\/wp-json\/wp\/v2\/tags?post=2290"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}