{"id":2262,"date":"2019-07-19T09:49:16","date_gmt":"2019-07-19T17:49:16","guid":{"rendered":"https:\/\/devblogs.microsoft.com\/typescript\/?p=2262"},"modified":"2019-07-19T09:49:16","modified_gmt":"2019-07-19T17:49:16","slug":"announcing-typescript-3-6-beta","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/typescript\/announcing-typescript-3-6-beta\/","title":{"rendered":"Announcing TypeScript 3.6 Beta"},"content":{"rendered":"<p>Today we&#8217;re happy to announce the availability of TypeScript 3.6 Beta. This beta is intended to be a feature-complete version of TypeScript 3.6. In the coming weeks we&#8217;ll be working on bugs and improving performance and stability for our release candidate, and eventually the full release.<\/p>\n<p>To get started using the beta, 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@beta<\/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-36beta\" 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 id=\"stricter-generators\">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 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 id=\"more-accurate-array-spread\">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:\/\/devblogs.microsoft.com\/typescript\/wp-content\/uploads\/sites\/11\/2019\/07\/add-missing-await-ts-36.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 id=\"semicolon-edits\">Semicolon-Aware Code Edits<\/h2>\n<p>Editors like Visual Studio and Visual Studio Code can do 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 id=\"breaking-changes\">Breaking Changes<\/h2>\n<h3>String-Named Methods Named <code>\"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><code>GlobalFetch<\/code> is gone. Instead, use <code>WindowOrWorkerGlobalScope<\/code><\/li>\n<li>Certian 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<h2>What&#8217;s Next?<\/h2>\n<p>TypeScript 3.6 is slated for the end of August, with a Release Candidate a few weeks prior. We hope you give the beta 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 TypeScript 3.6 Beta. This beta is intended to be a feature-complete version of TypeScript 3.6. In the coming weeks we&#8217;ll be working on bugs and improving performance and stability for our release candidate, and eventually the full release. To get started using the beta, you can get [&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-2262","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 TypeScript 3.6 Beta. This beta is intended to be a feature-complete version of TypeScript 3.6. In the coming weeks we&#8217;ll be working on bugs and improving performance and stability for our release candidate, and eventually the full release. To get started using the beta, you can get [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/typescript\/wp-json\/wp\/v2\/posts\/2262","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=2262"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/typescript\/wp-json\/wp\/v2\/posts\/2262\/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=2262"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/typescript\/wp-json\/wp\/v2\/categories?post=2262"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/typescript\/wp-json\/wp\/v2\/tags?post=2262"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}