{"id":3286,"date":"2022-02-28T16:01:33","date_gmt":"2022-03-01T00:01:33","guid":{"rendered":"https:\/\/devblogs.microsoft.com\/typescript\/?p=3286"},"modified":"2022-03-14T15:31:30","modified_gmt":"2022-03-14T23:31:30","slug":"announcing-typescript-4-6","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/typescript\/announcing-typescript-4-6\/","title":{"rendered":"Announcing TypeScript 4.6"},"content":{"rendered":"<p>Today we&#8217;re announcing the availability of TypeScript 4.6.<\/p>\n<p>If you&#8217;re not yet familiar with TypeScript, it&#8217;s a language that builds on JavaScript and adds syntax for types.\nTypes help describe what kinds of values you&#8217;re working with and what kinds of functions you&#8217;re calling.\nTypeScript can use this information to help you avoid about mistakes like typos, missing arguments, or forgetting to check for <code>null<\/code> and <code>undefined<\/code>!\nBut this type-checking isn&#8217;t the only thing TypeScript does &#8211; it uses the information from these types to give you an amazing editing experience, powering things like code-completions, go-to-definition, renaming, and more.\nIf you already use JavaScript in Visual Studio or Visual Studio Code, you&#8217;ve already been using TypeScript indirectly!<\/p>\n<p>To get started using TypeScript, you can get it <a href=\"https:\/\/www.nuget.org\/packages\/Microsoft.TypeScript.MSBuild\">through NuGet<\/a>, or use npm with the following command:<\/p>\n<pre class=\"lang:default decode:true\" style=\"background-color: #f0f0f0;padding: 10px;border-radius: 10px;\"><code><span style=\"color: #000000;\">npm install typescript<\/span>\r\n<\/code><\/pre>\n<p>You can also get editor support by<\/p>\n<ul>\n<li><a href=\"https:\/\/marketplace.visualstudio.com\/items?itemName=TypeScriptTeam.TypeScript-46\">Downloading for Visual Studio 2022\/2019<\/a><\/li>\n<li><a href=\"http:\/\/code.visualstudio.com\/insiders\">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\">use a newer version of TypeScript<\/a><\/li>\n<li><a href=\"https:\/\/packagecontrol.io\/packages\/TypeScript\">Using Package Control for Sublime Text 3<\/a>.<\/li>\n<\/ul>\n<p>If you&#8217;ve already read <a href=\"https:\/\/devblogs.microsoft.com\/typescript\/announcing-typescript-4-6-beta\/\">our beta<\/a> or <a href=\"https:\/\/devblogs.microsoft.com\/typescript\/announcing-typescript-4-6-rc\/\">RC blog posts<\/a>, you can <a href=\"#beta-delta\">read up on what&#8217;s changed since<\/a>.<\/p>\n<p>Here&#8217;s a quick list of what&#8217;s new in TypeScript 4.6!<\/p>\n<ul>\n<li><a href=\"#code-before-super\">Allowing Code in Constructors Before <code>super()<\/code><\/a><\/li>\n<li><a href=\"#cfa-destructured-discriminated-unions\">Control Flow Analysis for Destructured Discriminated Unions<\/a><\/li>\n<li><a href=\"#improved-depth-checks\">Improved Recursion Depth Checks<\/a><\/li>\n<li><a href=\"#indexed-access-inference-improvements\">Indexed Access Inference Improvements<\/a><\/li>\n<li><a href=\"#dependent-parameters-cfa\">Control Flow Analysis for Dependent Parameters<\/a><\/li>\n<li><a href=\"#target-es2022\"><code>--target es2022<\/code><\/a><\/li>\n<li><a href=\"#no-void-0-react-jsx\">Removed Unnecessary Arguments in <code>react-jsx<\/code><\/a><\/li>\n<li><a href=\"#jsdoc-name-suggestions\">JSDoc Name Suggestions<\/a><\/li>\n<li><a href=\"#syntax-errors-js\">More Syntax and Binding Errors in JavaScript<\/a><\/li>\n<li><a href=\"#typescript-trace-analyzer\">TypeScript Trace Analyzer<\/a><\/li>\n<li><a href=\"#breaking-changes\">Breaking Changes<\/a><\/li>\n<\/ul>\n<h2><a name=\"beta-delta\"><\/a> What&#8217;s New Since the Beta and RC?<\/h2>\n<p>When we announced our beta, we missed documenting two great features &#8211; <a href=\"#cfa-destructured-discriminated-unions\">control flow analysis for destructured discriminated unions<\/a> and <a href=\"#target-es2022\">the addition of the <code>es2022<\/code><\/a> output target.\nAn additional noteworthy change that has been present since our beta is <a href=\"#no-void-0-react-jsx\">the removal of <code>void 0<\/code> arguments in the <code>react-jsx<\/code> mode<\/a><\/p>\n<p>One change that made its way to our RC, but which we didn&#8217;t capture in our prior announcement was <a href=\"#jsdoc-name-suggestions\">suggestions for mismatched JSDoc parameter names<\/a>.<\/p>\n<p>Since our RC, we&#8217;ve also done some internal refactoring which has fixed certain issues, corrected some bizarre error messages, and improved type-checking performance by 3% in certain cases.\nYou can <a href=\"https:\/\/github.com\/microsoft\/TypeScript\/pull\/47738\">read up more on that change here<\/a>.<\/p>\n<h2><a name=\"code-before-super\"><\/a> Allowing Code in Constructors Before <code>super()<\/code><\/h2>\n<p>In JavaScript classes it&#8217;s mandatory to call <code>super()<\/code> before referring to <code>this<\/code>.\nTypeScript enforces this as well, though it was a bit too strict in <em>how<\/em> it ensured this.\nIn TypeScript, it was previously an error to contain <em>any<\/em> code at the beginning of a constructor if its containing class had any property initializers.<\/p>\n<pre class=\"lang:default decode:true\" style=\"background-color: #f0f0f0;padding: 10px;border-radius: 10px;\"><code><span style=\"color: #0000FF;\">class<\/span><span style=\"color: #000000;\"> <\/span><span style=\"color: #267F99;\">Base<\/span><span style=\"color: #000000;\"> {<\/span>\r\n<span style=\"color: #000000;\">    <\/span><span style=\"color: #008000;\">\/\/ ...<\/span>\r\n<span style=\"color: #000000;\">}<\/span>\r\n\r\n<span style=\"color: #0000FF;\">class<\/span><span style=\"color: #000000;\"> <\/span><span style=\"color: #267F99;\">Derived<\/span><span style=\"color: #000000;\"> <\/span><span style=\"color: #0000FF;\">extends<\/span><span style=\"color: #000000;\"> <\/span><span style=\"color: #267F99;\">Base<\/span><span style=\"color: #000000;\"> {<\/span>\r\n<span style=\"color: #000000;\">    <\/span><span style=\"color: #001080;\">someProperty<\/span><span style=\"color: #000000;\"> = <\/span><span style=\"color: #0000FF;\">true<\/span><span style=\"color: #000000;\">;<\/span>\r\n\r\n<span style=\"color: #000000;\">    <\/span><span style=\"color: #0000FF;\">constructor<\/span><span style=\"color: #000000;\">() {<\/span>\r\n<span style=\"color: #000000;\">        <\/span><span style=\"color: #008000;\">\/\/ error!<\/span>\r\n<span style=\"color: #000000;\">        <\/span><span style=\"color: #008000;\">\/\/ have to call 'super()' first because it needs to initialize 'someProperty'.<\/span>\r\n<span style=\"color: #000000;\">        <\/span><span style=\"color: #795E26;\">doSomeStuff<\/span><span style=\"color: #000000;\">();<\/span>\r\n<span style=\"color: #000000;\">        <\/span><span style=\"color: #0000FF;\">super<\/span><span style=\"color: #000000;\">();<\/span>\r\n<span style=\"color: #000000;\">    }<\/span>\r\n<span style=\"color: #000000;\">}<\/span>\r\n<\/code><\/pre>\n<p>This made it cheap to check that <code>super()<\/code> gets called before <code>this<\/code> is referenced, but it ended up rejecting a lot of valid code.\nTypeScript 4.6 is now much more lenient in that check and permits other code to run before <code>super()<\/code>., all while still ensuring that <code>super()<\/code> occurs at the top-level before any references to <code>this<\/code>.<\/p>\n<p>We&#8217;d like to extend our thanks to <a href=\"https:\/\/github.com\/JoshuaKGoldberg\">Joshua Goldberg<\/a> for <a href=\"https:\/\/github.com\/microsoft\/TypeScript\/pull\/29374\">patiently working with us to land this change<\/a>!<\/p>\n<h2><a name=\"cfa-destructured-discriminated-unions\"><\/a> Control Flow Analysis for Destructured Discriminated Unions<\/h2>\n<p>TypeScript is able to narrow types based on what&#8217;s called a discriminant property.\nFor example, in the following code snippet, TypeScript is able to narrow the type of <code>action<\/code> based on every time we check against the value of <code>kind<\/code>.<\/p>\n<pre class=\"lang:default decode:true\" style=\"background-color: #f0f0f0;padding: 10px;border-radius: 10px;\"><code><span style=\"color: #0000FF;\">type<\/span><span style=\"color: #000000;\"> <\/span><span style=\"color: #267F99;\">Action<\/span><span style=\"color: #000000;\"> =<\/span>\r\n<span style=\"color: #000000;\">    | { <\/span><span style=\"color: #001080;\">kind<\/span><span style=\"color: #000000;\">: <\/span><span style=\"color: #A31515;\">&quot;NumberContents&quot;<\/span><span style=\"color: #000000;\">, <\/span><span style=\"color: #001080;\">payload<\/span><span style=\"color: #000000;\">: <\/span><span style=\"color: #267F99;\">number<\/span><span style=\"color: #000000;\"> }<\/span>\r\n<span style=\"color: #000000;\">    | { <\/span><span style=\"color: #001080;\">kind<\/span><span style=\"color: #000000;\">: <\/span><span style=\"color: #A31515;\">&quot;StringContents&quot;<\/span><span style=\"color: #000000;\">, <\/span><span style=\"color: #001080;\">payload<\/span><span style=\"color: #000000;\">: <\/span><span style=\"color: #267F99;\">string<\/span><span style=\"color: #000000;\"> };<\/span>\r\n\r\n<span style=\"color: #0000FF;\">function<\/span><span style=\"color: #000000;\"> <\/span><span style=\"color: #795E26;\">processAction<\/span><span style=\"color: #000000;\">(<\/span><span style=\"color: #001080;\">action<\/span><span style=\"color: #000000;\">: <\/span><span style=\"color: #267F99;\">Action<\/span><span style=\"color: #000000;\">) {<\/span>\r\n<span style=\"color: #000000;\">    <\/span><span style=\"color: #AF00DB;\">if<\/span><span style=\"color: #000000;\"> (<\/span><span style=\"color: #001080;\">action<\/span><span style=\"color: #000000;\">.<\/span><span style=\"color: #001080;\">kind<\/span><span style=\"color: #000000;\"> === <\/span><span style=\"color: #A31515;\">&quot;NumberContents&quot;<\/span><span style=\"color: #000000;\">) {<\/span>\r\n<span style=\"color: #000000;\">        <\/span><span style=\"color: #008000;\">\/\/ `action.payload` is a number here.<\/span>\r\n<span style=\"color: #000000;\">        <\/span><span style=\"color: #0000FF;\">let<\/span><span style=\"color: #000000;\"> <\/span><span style=\"color: #001080;\">num<\/span><span style=\"color: #000000;\"> = <\/span><span style=\"color: #001080;\">action<\/span><span style=\"color: #000000;\">.<\/span><span style=\"color: #001080;\">payload<\/span><span style=\"color: #000000;\"> * <\/span><span style=\"color: #098658;\">2<\/span>\r\n<span style=\"color: #000000;\">        <\/span><span style=\"color: #008000;\">\/\/ ...<\/span>\r\n<span style=\"color: #000000;\">    }<\/span>\r\n<span style=\"color: #000000;\">    <\/span><span style=\"color: #AF00DB;\">else<\/span><span style=\"color: #000000;\"> <\/span><span style=\"color: #AF00DB;\">if<\/span><span style=\"color: #000000;\"> (<\/span><span style=\"color: #001080;\">action<\/span><span style=\"color: #000000;\">.<\/span><span style=\"color: #001080;\">kind<\/span><span style=\"color: #000000;\"> === <\/span><span style=\"color: #A31515;\">&quot;StringContents&quot;<\/span><span style=\"color: #000000;\">) {<\/span>\r\n<span style=\"color: #000000;\">        <\/span><span style=\"color: #008000;\">\/\/ `action.payload` is a string here.<\/span>\r\n<span style=\"color: #000000;\">        <\/span><span style=\"color: #0000FF;\">const<\/span><span style=\"color: #000000;\"> <\/span><span style=\"color: #0070C1;\">str<\/span><span style=\"color: #000000;\"> = <\/span><span style=\"color: #001080;\">action<\/span><span style=\"color: #000000;\">.<\/span><span style=\"color: #001080;\">payload<\/span><span style=\"color: #000000;\">.<\/span><span style=\"color: #795E26;\">trim<\/span><span style=\"color: #000000;\">();<\/span>\r\n<span style=\"color: #000000;\">        <\/span><span style=\"color: #008000;\">\/\/ ...<\/span>\r\n<span style=\"color: #000000;\">    }<\/span>\r\n<span style=\"color: #000000;\">}<\/span>\r\n<\/code><\/pre>\n<p>This lets us work with objects that can hold different data, but a common field tells us <em>which<\/em> data those objects have.<\/p>\n<p>This is very common in TypeScript; however, depending on your preferences, you might have wanted to destructure <code>kind<\/code> and <code>payload<\/code> in the the example above.\nPerhaps something like the following:<\/p>\n<pre class=\"lang:default decode:true\" style=\"background-color: #f0f0f0;padding: 10px;border-radius: 10px;\"><code><span style=\"color: #0000FF;\">type<\/span><span style=\"color: #000000;\"> <\/span><span style=\"color: #267F99;\">Action<\/span><span style=\"color: #000000;\"> =<\/span>\r\n<span style=\"color: #000000;\">    | { <\/span><span style=\"color: #001080;\">kind<\/span><span style=\"color: #000000;\">: <\/span><span style=\"color: #A31515;\">&quot;NumberContents&quot;<\/span><span style=\"color: #000000;\">, <\/span><span style=\"color: #001080;\">payload<\/span><span style=\"color: #000000;\">: <\/span><span style=\"color: #267F99;\">number<\/span><span style=\"color: #000000;\"> }<\/span>\r\n<span style=\"color: #000000;\">    | { <\/span><span style=\"color: #001080;\">kind<\/span><span style=\"color: #000000;\">: <\/span><span style=\"color: #A31515;\">&quot;StringContents&quot;<\/span><span style=\"color: #000000;\">, <\/span><span style=\"color: #001080;\">payload<\/span><span style=\"color: #000000;\">: <\/span><span style=\"color: #267F99;\">string<\/span><span style=\"color: #000000;\"> };<\/span>\r\n\r\n<span style=\"color: #0000FF;\">function<\/span><span style=\"color: #000000;\"> <\/span><span style=\"color: #795E26;\">processAction<\/span><span style=\"color: #000000;\">(<\/span><span style=\"color: #001080;\">action<\/span><span style=\"color: #000000;\">: <\/span><span style=\"color: #267F99;\">Action<\/span><span style=\"color: #000000;\">) {<\/span>\r\n<span style=\"color: #000000;\">    <\/span><span style=\"color: #0000FF;\">const<\/span><span style=\"color: #000000;\"> { <\/span><span style=\"color: #0070C1;\">kind<\/span><span style=\"color: #000000;\">, <\/span><span style=\"color: #0070C1;\">payload<\/span><span style=\"color: #000000;\"> } = <\/span><span style=\"color: #001080;\">action<\/span><span style=\"color: #000000;\">;<\/span>\r\n<span style=\"color: #000000;\">    <\/span><span style=\"color: #AF00DB;\">if<\/span><span style=\"color: #000000;\"> (<\/span><span style=\"color: #001080;\">kind<\/span><span style=\"color: #000000;\"> === <\/span><span style=\"color: #A31515;\">&quot;NumberContents&quot;<\/span><span style=\"color: #000000;\">) {<\/span>\r\n<span style=\"color: #000000;\">        <\/span><span style=\"color: #0000FF;\">let<\/span><span style=\"color: #000000;\"> <\/span><span style=\"color: #001080;\">num<\/span><span style=\"color: #000000;\"> = <\/span><span style=\"color: #001080;\">payload<\/span><span style=\"color: #000000;\"> * <\/span><span style=\"color: #098658;\">2<\/span>\r\n<span style=\"color: #000000;\">        <\/span><span style=\"color: #008000;\">\/\/ ...<\/span>\r\n<span style=\"color: #000000;\">    }<\/span>\r\n<span style=\"color: #000000;\">    <\/span><span style=\"color: #AF00DB;\">else<\/span><span style=\"color: #000000;\"> <\/span><span style=\"color: #AF00DB;\">if<\/span><span style=\"color: #000000;\"> (<\/span><span style=\"color: #001080;\">kind<\/span><span style=\"color: #000000;\"> === <\/span><span style=\"color: #A31515;\">&quot;StringContents&quot;<\/span><span style=\"color: #000000;\">) {<\/span>\r\n<span style=\"color: #000000;\">        <\/span><span style=\"color: #0000FF;\">const<\/span><span style=\"color: #000000;\"> <\/span><span style=\"color: #0070C1;\">str<\/span><span style=\"color: #000000;\"> = <\/span><span style=\"color: #001080;\">payload<\/span><span style=\"color: #000000;\">.<\/span><span style=\"color: #795E26;\">trim<\/span><span style=\"color: #000000;\">();<\/span>\r\n<span style=\"color: #000000;\">        <\/span><span style=\"color: #008000;\">\/\/ ...<\/span>\r\n<span style=\"color: #000000;\">    }<\/span>\r\n<span style=\"color: #000000;\">}<\/span>\r\n\r\n<\/code><\/pre>\n<p>Previously TypeScript would error on these &#8211; once <code>kind<\/code> and <code>payload<\/code> were extracted from the same object into variables, they were considered totally independent.<\/p>\n<p>In TypeScript 4.6, this just works!<\/p>\n<p>When destructuring individual properties into a <code>const<\/code> declaration, or when destructuring a parameter into variables that are never assigned to, TypeScript will check for if the destructured type is a discriminated union.\nIf it is, TypeScript can now narrow the types of variables depending on checks of other variables\nSo in our example, a check on <code>kind<\/code> narrows the type of <code>payload<\/code>.<\/p>\n<p>For more information, <a href=\"https:\/\/github.com\/microsoft\/TypeScript\/pull\/46266\">see the pull request that implemented this analysis<\/a>.<\/p>\n<h2><a name=\"improved-depth-checks\"><\/a> Improved Recursion Depth Checks<\/h2>\n<p>TypeScript has some interesting challenges due to the fact that it&#8217;s built on a structural type system that also provides generics.<\/p>\n<p>In a structural type system, object types are compatible based on the members they have.<\/p>\n<pre class=\"lang:default decode:true\" style=\"background-color: #f0f0f0;padding: 10px;border-radius: 10px;\"><code><span style=\"color: #0000FF;\">interface<\/span><span style=\"color: #000000;\"> <\/span><span style=\"color: #267F99;\">Source<\/span><span style=\"color: #000000;\"> {<\/span>\r\n<span style=\"color: #000000;\">    <\/span><span style=\"color: #001080;\">prop<\/span><span style=\"color: #000000;\">: <\/span><span style=\"color: #267F99;\">string<\/span><span style=\"color: #000000;\">;<\/span>\r\n<span style=\"color: #000000;\">}<\/span>\r\n\r\n<span style=\"color: #0000FF;\">interface<\/span><span style=\"color: #000000;\"> <\/span><span style=\"color: #267F99;\">Target<\/span><span style=\"color: #000000;\"> {<\/span>\r\n<span style=\"color: #000000;\">    <\/span><span style=\"color: #001080;\">prop<\/span><span style=\"color: #000000;\">: <\/span><span style=\"color: #267F99;\">number<\/span><span style=\"color: #000000;\">;<\/span>\r\n<span style=\"color: #000000;\">}<\/span>\r\n\r\n<span style=\"color: #0000FF;\">function<\/span><span style=\"color: #000000;\"> <\/span><span style=\"color: #795E26;\">check<\/span><span style=\"color: #000000;\">(<\/span><span style=\"color: #001080;\">source<\/span><span style=\"color: #000000;\">: <\/span><span style=\"color: #267F99;\">Source<\/span><span style=\"color: #000000;\">, <\/span><span style=\"color: #001080;\">target<\/span><span style=\"color: #000000;\">: <\/span><span style=\"color: #267F99;\">Target<\/span><span style=\"color: #000000;\">) {<\/span>\r\n<span style=\"color: #000000;\">    <\/span><span style=\"color: #001080;\">target<\/span><span style=\"color: #000000;\"> = <\/span><span style=\"color: #001080;\">source<\/span><span style=\"color: #000000;\">;<\/span>\r\n<span style=\"color: #000000;\">    <\/span><span style=\"color: #008000;\">\/\/ error!<\/span>\r\n<span style=\"color: #000000;\">    <\/span><span style=\"color: #008000;\">\/\/ Type 'Source' is not assignable to type 'Target'.<\/span>\r\n<span style=\"color: #000000;\">    <\/span><span style=\"color: #008000;\">\/\/   Types of property 'prop' are incompatible.<\/span>\r\n<span style=\"color: #000000;\">    <\/span><span style=\"color: #008000;\">\/\/     Type 'string' is not assignable to type 'number'.<\/span>\r\n<span style=\"color: #000000;\">}<\/span>\r\n<\/code><\/pre>\n<p>Notice that whether or not <code>Source<\/code> is compatible with <code>Target<\/code> has to do with whether their <em>properties<\/em> are assignable.\nIn this case, that&#8217;s just <code>prop<\/code>.<\/p>\n<p>When you introduce generics into this, there are some harder questions to answer.\nFor instance, is a <code>Source&lt;string&gt;<\/code> assignable to a <code>Target&lt;number&gt;<\/code> in the following case?<\/p>\n<pre class=\"lang:default decode:true\" style=\"background-color: #f0f0f0;padding: 10px;border-radius: 10px;\"><code><span style=\"color: #0000FF;\">interface<\/span><span style=\"color: #000000;\"> <\/span><span style=\"color: #267F99;\">Source<\/span><span style=\"color: #000000;\">&lt;<\/span><span style=\"color: #267F99;\">T<\/span><span style=\"color: #000000;\">&gt; {<\/span>\r\n<span style=\"color: #000000;\">    <\/span><span style=\"color: #001080;\">prop<\/span><span style=\"color: #000000;\">: <\/span><span style=\"color: #267F99;\">Source<\/span><span style=\"color: #000000;\">&lt;<\/span><span style=\"color: #267F99;\">Source<\/span><span style=\"color: #000000;\">&lt;<\/span><span style=\"color: #267F99;\">T<\/span><span style=\"color: #000000;\">&gt;&gt;;<\/span>\r\n<span style=\"color: #000000;\">}<\/span>\r\n\r\n<span style=\"color: #0000FF;\">interface<\/span><span style=\"color: #000000;\"> <\/span><span style=\"color: #267F99;\">Target<\/span><span style=\"color: #000000;\">&lt;<\/span><span style=\"color: #267F99;\">T<\/span><span style=\"color: #000000;\">&gt; {<\/span>\r\n<span style=\"color: #000000;\">    <\/span><span style=\"color: #001080;\">prop<\/span><span style=\"color: #000000;\">: <\/span><span style=\"color: #267F99;\">Target<\/span><span style=\"color: #000000;\">&lt;<\/span><span style=\"color: #267F99;\">Target<\/span><span style=\"color: #000000;\">&lt;<\/span><span style=\"color: #267F99;\">T<\/span><span style=\"color: #000000;\">&gt;&gt;;<\/span>\r\n<span style=\"color: #000000;\">}<\/span>\r\n\r\n<span style=\"color: #0000FF;\">function<\/span><span style=\"color: #000000;\"> <\/span><span style=\"color: #795E26;\">check<\/span><span style=\"color: #000000;\">(<\/span><span style=\"color: #001080;\">source<\/span><span style=\"color: #000000;\">: <\/span><span style=\"color: #267F99;\">Source<\/span><span style=\"color: #000000;\">&lt;<\/span><span style=\"color: #267F99;\">string<\/span><span style=\"color: #000000;\">&gt;, <\/span><span style=\"color: #001080;\">target<\/span><span style=\"color: #000000;\">: <\/span><span style=\"color: #267F99;\">Target<\/span><span style=\"color: #000000;\">&lt;<\/span><span style=\"color: #267F99;\">number<\/span><span style=\"color: #000000;\">&gt;) {<\/span>\r\n<span style=\"color: #000000;\">    <\/span><span style=\"color: #001080;\">target<\/span><span style=\"color: #000000;\"> = <\/span><span style=\"color: #001080;\">source<\/span><span style=\"color: #000000;\">;<\/span>\r\n<span style=\"color: #000000;\">}<\/span>\r\n<\/code><\/pre>\n<p>In order to answer that, TypeScript needs to check whether the types of <code>prop<\/code> are compatible.\nThat leads to the another question: is a <code>Source&lt;Source&lt;string&gt;&gt;<\/code> assignable to a <code>Target&lt;Target&lt;number&gt;&gt;<\/code>?\nTo answer that, TypeScript checks whether <code>prop<\/code> is compatible for <em>those<\/em> types, and ends up checking whether <code>Source&lt;Source&lt;Source&lt;string&gt;&gt;&gt;<\/code> is assignable to <code>Target&lt;Target&lt;Target&lt;number&gt;&gt;&gt;<\/code>.\nKeep going for a bit, and you might notice that the type infinitely expands the more you dig in.<\/p>\n<p>TypeScript has a few heuristics here &#8211; if a type <em>appears<\/em> to be infinitely expanding after encountering a certain depth check, then it considers that the types <em>could<\/em> be compatible.\nThis is usually enough, but embarrassingly there were some false-negatives that this wouldn&#8217;t catch.<\/p>\n<pre class=\"lang:default decode:true\" style=\"background-color: #f0f0f0;padding: 10px;border-radius: 10px;\"><code><span style=\"color: #0000FF;\">interface<\/span><span style=\"color: #000000;\"> <\/span><span style=\"color: #267F99;\">Foo<\/span><span style=\"color: #000000;\">&lt;<\/span><span style=\"color: #267F99;\">T<\/span><span style=\"color: #000000;\">&gt; {<\/span>\r\n<span style=\"color: #000000;\">    <\/span><span style=\"color: #001080;\">prop<\/span><span style=\"color: #000000;\">: <\/span><span style=\"color: #267F99;\">T<\/span><span style=\"color: #000000;\">;<\/span>\r\n<span style=\"color: #000000;\">}<\/span>\r\n\r\n<span style=\"color: #0000FF;\">declare<\/span><span style=\"color: #000000;\"> <\/span><span style=\"color: #0000FF;\">let<\/span><span style=\"color: #000000;\"> <\/span><span style=\"color: #001080;\">x<\/span><span style=\"color: #000000;\">: <\/span><span style=\"color: #267F99;\">Foo<\/span><span style=\"color: #000000;\">&lt;<\/span><span style=\"color: #267F99;\">Foo<\/span><span style=\"color: #000000;\">&lt;<\/span><span style=\"color: #267F99;\">Foo<\/span><span style=\"color: #000000;\">&lt;<\/span><span style=\"color: #267F99;\">Foo<\/span><span style=\"color: #000000;\">&lt;<\/span><span style=\"color: #267F99;\">Foo<\/span><span style=\"color: #000000;\">&lt;<\/span><span style=\"color: #267F99;\">Foo<\/span><span style=\"color: #000000;\">&lt;<\/span><span style=\"color: #267F99;\">string<\/span><span style=\"color: #000000;\">&gt;&gt;&gt;&gt;&gt;&gt;;<\/span>\r\n<span style=\"color: #0000FF;\">declare<\/span><span style=\"color: #000000;\"> <\/span><span style=\"color: #0000FF;\">let<\/span><span style=\"color: #000000;\"> <\/span><span style=\"color: #001080;\">y<\/span><span style=\"color: #000000;\">: <\/span><span style=\"color: #267F99;\">Foo<\/span><span style=\"color: #000000;\">&lt;<\/span><span style=\"color: #267F99;\">Foo<\/span><span style=\"color: #000000;\">&lt;<\/span><span style=\"color: #267F99;\">Foo<\/span><span style=\"color: #000000;\">&lt;<\/span><span style=\"color: #267F99;\">Foo<\/span><span style=\"color: #000000;\">&lt;<\/span><span style=\"color: #267F99;\">Foo<\/span><span style=\"color: #000000;\">&lt;<\/span><span style=\"color: #267F99;\">string<\/span><span style=\"color: #000000;\">&gt;&gt;&gt;&gt;&gt;;<\/span>\r\n\r\n<span style=\"color: #001080;\">x<\/span><span style=\"color: #000000;\"> = <\/span><span style=\"color: #001080;\">y<\/span><span style=\"color: #000000;\">;<\/span>\r\n<\/code><\/pre>\n<p>A human reader can see that <code>x<\/code> and <code>y<\/code> should be incompatible in the above example.\nWhile the types are deeply nested, that&#8217;s just a consequence of how they were declared.\nThe heuristic was meant to capture cases where deeply-nested types were generated through exploring the types, not from when a developer wrote that type out themselves.<\/p>\n<p>TypeScript 4.6 is now able to distinguish these cases, and correctly errors on the last example.\nAdditionally, because the language is no longer concerned with false-positives from explicitly-written types, TypeScript can conclude that a type is infinitely expanding much earlier, and save a bunch of work in checking for type compatibility.\nAs a result, libraries on DefinitelyTyped like <code>redux-immutable<\/code>, <code>react-lazylog<\/code>, and <code>yup<\/code> saw a 50% reduction in check-time.<\/p>\n<p>You may already have this change because it was cherry-picked into TypeScript 4.5.3, but it is a notable feature of TypeScript 4.6 which you can read up more about <a href=\"https:\/\/github.com\/microsoft\/TypeScript\/pull\/46599\">here<\/a>.<\/p>\n<h2><a name=\"indexed-access-inference-improvements\"><\/a> Indexed Access Inference Improvements<\/h2>\n<p>TypeScript now can correctly infer to indexed access types which immediately index into a mapped object type.<\/p>\n<pre class=\"lang:default decode:true\" style=\"background-color: #f0f0f0;padding: 10px;border-radius: 10px;\"><code><span style=\"color: #0000FF;\">interface<\/span><span style=\"color: #000000;\"> <\/span><span style=\"color: #267F99;\">TypeMap<\/span><span style=\"color: #000000;\"> {<\/span>\r\n<span style=\"color: #000000;\">    <\/span><span style=\"color: #A31515;\">&quot;number&quot;<\/span><span style=\"color: #000000;\">: <\/span><span style=\"color: #267F99;\">number<\/span><span style=\"color: #000000;\">;<\/span>\r\n<span style=\"color: #000000;\">    <\/span><span style=\"color: #A31515;\">&quot;string&quot;<\/span><span style=\"color: #000000;\">: <\/span><span style=\"color: #267F99;\">string<\/span><span style=\"color: #000000;\">;<\/span>\r\n<span style=\"color: #000000;\">    <\/span><span style=\"color: #A31515;\">&quot;boolean&quot;<\/span><span style=\"color: #000000;\">: <\/span><span style=\"color: #267F99;\">boolean<\/span><span style=\"color: #000000;\">;<\/span>\r\n<span style=\"color: #000000;\">}<\/span>\r\n\r\n<span style=\"color: #0000FF;\">type<\/span><span style=\"color: #000000;\"> <\/span><span style=\"color: #267F99;\">UnionRecord<\/span><span style=\"color: #000000;\">&lt;<\/span><span style=\"color: #267F99;\">P<\/span><span style=\"color: #000000;\"> <\/span><span style=\"color: #0000FF;\">extends<\/span><span style=\"color: #000000;\"> <\/span><span style=\"color: #0000FF;\">keyof<\/span><span style=\"color: #000000;\"> <\/span><span style=\"color: #267F99;\">TypeMap<\/span><span style=\"color: #000000;\">&gt; = { [<\/span><span style=\"color: #267F99;\">K<\/span><span style=\"color: #000000;\"> <\/span><span style=\"color: #0000FF;\">in<\/span><span style=\"color: #000000;\"> <\/span><span style=\"color: #267F99;\">P<\/span><span style=\"color: #000000;\">]:<\/span>\r\n<span style=\"color: #000000;\">    {<\/span>\r\n<span style=\"color: #000000;\">        <\/span><span style=\"color: #001080;\">kind<\/span><span style=\"color: #000000;\">: <\/span><span style=\"color: #267F99;\">K<\/span><span style=\"color: #000000;\">;<\/span>\r\n<span style=\"color: #000000;\">        <\/span><span style=\"color: #001080;\">v<\/span><span style=\"color: #000000;\">: <\/span><span style=\"color: #267F99;\">TypeMap<\/span><span style=\"color: #000000;\">[<\/span><span style=\"color: #267F99;\">K<\/span><span style=\"color: #000000;\">];<\/span>\r\n<span style=\"color: #000000;\">        <\/span><span style=\"color: #795E26;\">f<\/span><span style=\"color: #000000;\">: (<\/span><span style=\"color: #001080;\">p<\/span><span style=\"color: #000000;\">: <\/span><span style=\"color: #267F99;\">TypeMap<\/span><span style=\"color: #000000;\">[<\/span><span style=\"color: #267F99;\">K<\/span><span style=\"color: #000000;\">]) <\/span><span style=\"color: #0000FF;\">=&gt;<\/span><span style=\"color: #000000;\"> <\/span><span style=\"color: #267F99;\">void<\/span><span style=\"color: #000000;\">;<\/span>\r\n<span style=\"color: #000000;\">    }<\/span>\r\n<span style=\"color: #000000;\">}[<\/span><span style=\"color: #267F99;\">P<\/span><span style=\"color: #000000;\">];<\/span>\r\n\r\n<span style=\"color: #0000FF;\">function<\/span><span style=\"color: #000000;\"> <\/span><span style=\"color: #795E26;\">processRecord<\/span><span style=\"color: #000000;\">&lt;<\/span><span style=\"color: #267F99;\">K<\/span><span style=\"color: #000000;\"> <\/span><span style=\"color: #0000FF;\">extends<\/span><span style=\"color: #000000;\"> <\/span><span style=\"color: #0000FF;\">keyof<\/span><span style=\"color: #000000;\"> <\/span><span style=\"color: #267F99;\">TypeMap<\/span><span style=\"color: #000000;\">&gt;(<\/span><span style=\"color: #001080;\">record<\/span><span style=\"color: #000000;\">: <\/span><span style=\"color: #267F99;\">UnionRecord<\/span><span style=\"color: #000000;\">&lt;<\/span><span style=\"color: #267F99;\">K<\/span><span style=\"color: #000000;\">&gt;) {<\/span>\r\n<span style=\"color: #000000;\">    <\/span><span style=\"color: #001080;\">record<\/span><span style=\"color: #000000;\">.<\/span><span style=\"color: #795E26;\">f<\/span><span style=\"color: #000000;\">(<\/span><span style=\"color: #001080;\">record<\/span><span style=\"color: #000000;\">.<\/span><span style=\"color: #001080;\">v<\/span><span style=\"color: #000000;\">);<\/span>\r\n<span style=\"color: #000000;\">}<\/span>\r\n\r\n<span style=\"color: #008000;\">\/\/ This call used to have issues - now works!<\/span>\r\n<span style=\"color: #795E26;\">processRecord<\/span><span style=\"color: #000000;\">({<\/span>\r\n<span style=\"color: #000000;\">    <\/span><span style=\"color: #001080;\">kind:<\/span><span style=\"color: #000000;\"> <\/span><span style=\"color: #A31515;\">&quot;string&quot;<\/span><span style=\"color: #000000;\">,<\/span>\r\n<span style=\"color: #000000;\">    <\/span><span style=\"color: #001080;\">v:<\/span><span style=\"color: #000000;\"> <\/span><span style=\"color: #A31515;\">&quot;hello!&quot;<\/span><span style=\"color: #000000;\">,<\/span>\r\n\r\n<span style=\"color: #000000;\">    <\/span><span style=\"color: #008000;\">\/\/ 'val' used to implicitly have the type 'string | number | boolean',<\/span>\r\n<span style=\"color: #000000;\">    <\/span><span style=\"color: #008000;\">\/\/ but now is correctly inferred to just 'string'.<\/span>\r\n<span style=\"color: #000000;\">    <\/span><span style=\"color: #795E26;\">f<\/span><span style=\"color: #001080;\">:<\/span><span style=\"color: #000000;\"> <\/span><span style=\"color: #001080;\">val<\/span><span style=\"color: #000000;\"> <\/span><span style=\"color: #0000FF;\">=&gt;<\/span><span style=\"color: #000000;\"> {<\/span>\r\n<span style=\"color: #000000;\">        <\/span><span style=\"color: #001080;\">console<\/span><span style=\"color: #000000;\">.<\/span><span style=\"color: #795E26;\">log<\/span><span style=\"color: #000000;\">(<\/span><span style=\"color: #001080;\">val<\/span><span style=\"color: #000000;\">.<\/span><span style=\"color: #795E26;\">toUpperCase<\/span><span style=\"color: #000000;\">());<\/span>\r\n<span style=\"color: #000000;\">    }<\/span>\r\n<span style=\"color: #000000;\">})<\/span>\r\n<\/code><\/pre>\n<p>This pattern was already supported and allowed TypeScript to understand that the call to <code>record.f(record.v)<\/code> is valid, but previously the call to <code>processRecord<\/code> would give poor inference results for <code>val<\/code><\/p>\n<p>TypeScript 4.6 improves this so that no type assertions are necessary within the call to <code>processRecord<\/code>.<\/p>\n<p>For more information, you can <a href=\"https:\/\/github.com\/microsoft\/TypeScript\/pull\/47109\">read up on the pull request<\/a>.<\/p>\n<h2><a name=\"dependent-parameters-cfa\"><\/a> Control Flow Analysis for Dependent Parameters<\/h2>\n<p>A signature can be declared with a rest parameter whose type is a discriminated union of tuples.<\/p>\n<pre class=\"lang:default decode:true\" style=\"background-color: #f0f0f0;padding: 10px;border-radius: 10px;\"><code><span style=\"color: #0000FF;\">function<\/span><span style=\"color: #000000;\"> <\/span><span style=\"color: #795E26;\">func<\/span><span style=\"color: #000000;\">(...<\/span><span style=\"color: #001080;\">args<\/span><span style=\"color: #000000;\">: [<\/span><span style=\"color: #A31515;\">&quot;str&quot;<\/span><span style=\"color: #000000;\">, <\/span><span style=\"color: #267F99;\">string<\/span><span style=\"color: #000000;\">] | [<\/span><span style=\"color: #A31515;\">&quot;num&quot;<\/span><span style=\"color: #000000;\">, <\/span><span style=\"color: #267F99;\">number<\/span><span style=\"color: #000000;\">]) {<\/span>\r\n<span style=\"color: #000000;\">    <\/span><span style=\"color: #008000;\">\/\/ ...<\/span>\r\n<span style=\"color: #000000;\">}<\/span>\r\n<\/code><\/pre>\n<p>What this says is that the arguments to <code>func<\/code> depends entirely on the first argument.\nWhen the first argument is the string <code>&quot;str&quot;<\/code>, then its second argument has to be a <code>string<\/code>.\nWhen its first argument is the string <code>&quot;num&quot;<\/code>, its second argument has to be a <code>number<\/code>.<\/p>\n<p>In cases where TypeScript infers the type of a function from a signature like this, TypeScript can now narrow parameters that depend on each other.<\/p>\n<pre class=\"lang:default decode:true\" style=\"background-color: #f0f0f0;padding: 10px;border-radius: 10px;\"><code><span style=\"color: #0000FF;\">type<\/span><span style=\"color: #000000;\"> <\/span><span style=\"color: #267F99;\">Func<\/span><span style=\"color: #000000;\"> = (...<\/span><span style=\"color: #001080;\">args<\/span><span style=\"color: #000000;\">: [<\/span><span style=\"color: #A31515;\">&quot;a&quot;<\/span><span style=\"color: #000000;\">, <\/span><span style=\"color: #267F99;\">number<\/span><span style=\"color: #000000;\">] | [<\/span><span style=\"color: #A31515;\">&quot;b&quot;<\/span><span style=\"color: #000000;\">, <\/span><span style=\"color: #267F99;\">string<\/span><span style=\"color: #000000;\">]) <\/span><span style=\"color: #0000FF;\">=&gt;<\/span><span style=\"color: #000000;\"> <\/span><span style=\"color: #267F99;\">void<\/span><span style=\"color: #000000;\">;<\/span>\r\n\r\n<span style=\"color: #0000FF;\">const<\/span><span style=\"color: #000000;\"> <\/span><span style=\"color: #795E26;\">f1<\/span><span style=\"color: #000000;\">: <\/span><span style=\"color: #267F99;\">Func<\/span><span style=\"color: #000000;\"> = (<\/span><span style=\"color: #001080;\">kind<\/span><span style=\"color: #000000;\">, <\/span><span style=\"color: #001080;\">payload<\/span><span style=\"color: #000000;\">) <\/span><span style=\"color: #0000FF;\">=&gt;<\/span><span style=\"color: #000000;\"> {<\/span>\r\n<span style=\"color: #000000;\">    <\/span><span style=\"color: #AF00DB;\">if<\/span><span style=\"color: #000000;\"> (<\/span><span style=\"color: #001080;\">kind<\/span><span style=\"color: #000000;\"> === <\/span><span style=\"color: #A31515;\">&quot;a&quot;<\/span><span style=\"color: #000000;\">) {<\/span>\r\n<span style=\"color: #000000;\">        <\/span><span style=\"color: #001080;\">payload<\/span><span style=\"color: #000000;\">.<\/span><span style=\"color: #795E26;\">toFixed<\/span><span style=\"color: #000000;\">();  <\/span><span style=\"color: #008000;\">\/\/ 'payload' narrowed to 'number'<\/span>\r\n<span style=\"color: #000000;\">    }<\/span>\r\n<span style=\"color: #000000;\">    <\/span><span style=\"color: #AF00DB;\">if<\/span><span style=\"color: #000000;\"> (<\/span><span style=\"color: #001080;\">kind<\/span><span style=\"color: #000000;\"> === <\/span><span style=\"color: #A31515;\">&quot;b&quot;<\/span><span style=\"color: #000000;\">) {<\/span>\r\n<span style=\"color: #000000;\">        <\/span><span style=\"color: #001080;\">payload<\/span><span style=\"color: #000000;\">.<\/span><span style=\"color: #795E26;\">toUpperCase<\/span><span style=\"color: #000000;\">();  <\/span><span style=\"color: #008000;\">\/\/ 'payload' narrowed to 'string'<\/span>\r\n<span style=\"color: #000000;\">    }<\/span>\r\n<span style=\"color: #000000;\">};<\/span>\r\n\r\n<span style=\"color: #795E26;\">f1<\/span><span style=\"color: #000000;\">(<\/span><span style=\"color: #A31515;\">&quot;a&quot;<\/span><span style=\"color: #000000;\">, <\/span><span style=\"color: #098658;\">42<\/span><span style=\"color: #000000;\">);<\/span>\r\n<span style=\"color: #795E26;\">f1<\/span><span style=\"color: #000000;\">(<\/span><span style=\"color: #A31515;\">&quot;b&quot;<\/span><span style=\"color: #000000;\">, <\/span><span style=\"color: #A31515;\">&quot;hello&quot;<\/span><span style=\"color: #000000;\">);<\/span>\r\n<\/code><\/pre>\n<p>For more information, <a href=\"https:\/\/github.com\/microsoft\/TypeScript\/pull\/47190\">see the change on GitHub<\/a>.<\/p>\n<h2><a name=\"target-es2022\"><\/a> <code>--target es2022<\/code><\/h2>\n<p>TypeScript&#8217;s <code>--target<\/code> option now supports <code>es2022<\/code>.\nThis means features like class fields now have a stable output target where they can be preserved.\nIt also means that new built-in functionality like the <a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/JavaScript\/Reference\/Global_Objects\/Array\/at\"><code>at()<\/code> method on <code>Array<\/code>s<\/a>, <a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/JavaScript\/Reference\/Global_Objects\/Object\/hasOwn\"><code>Object.hasOwn<\/code><\/a>, or <a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/JavaScript\/Reference\/Global_Objects\/Error\/Error#rethrowing_an_error_with_a_cause\">the <code>cause<\/code> option on <code>new Error<\/code><\/a> can be used either with this new <code>--target<\/code> setting, or with <code>--lib es2022<\/code>.<\/p>\n<p>This functionality was <a href=\"https:\/\/github.com\/microsoft\/TypeScript\/pull\/46291\">implemented<\/a> by <a href=\"https:\/\/github.com\/saschanaz\">Kagami Sascha Rosylight (saschanaz)<\/a> over several PRs, and we&#8217;re grateful for that contribution!<\/p>\n<h2><a name=\"no-void-0-react-jsx\"><\/a> Removed Unnecessary Arguments in <code>react-jsx<\/code><\/h2>\n<p>Previously, when compiling code like the following in <code>--jsx react-jsx<\/code><\/p>\n<pre class=\"lang:default decode:true\" style=\"background-color: #f0f0f0;padding: 10px;border-radius: 10px;\"><code><span style=\"color: #AF00DB;\">export<\/span><span style=\"color: #000000;\"> <\/span><span style=\"color: #0000FF;\">const<\/span><span style=\"color: #000000;\"> <\/span><span style=\"color: #0070C1;\">el<\/span><span style=\"color: #000000;\"> = <\/span><span style=\"color: #800000;\">&lt;div&gt;<\/span><span style=\"color: #000000;\">foo<\/span><span style=\"color: #800000;\">&lt;\/div&gt;<\/span><span style=\"color: #000000;\">;<\/span>\r\n<\/code><\/pre>\n<p>TypeScript would produce the following JavaScript code:<\/p>\n<pre class=\"lang:default decode:true\" style=\"background-color: #f0f0f0;padding: 10px;border-radius: 10px;\"><code><span style=\"color: #AF00DB;\">import<\/span><span style=\"color: #000000;\"> { <\/span><span style=\"color: #001080;\">jsx<\/span><span style=\"color: #000000;\"> <\/span><span style=\"color: #AF00DB;\">as<\/span><span style=\"color: #000000;\"> <\/span><span style=\"color: #001080;\">_jsx<\/span><span style=\"color: #000000;\"> } <\/span><span style=\"color: #AF00DB;\">from<\/span><span style=\"color: #000000;\"> <\/span><span style=\"color: #A31515;\">&quot;react\/jsx-runtime&quot;<\/span><span style=\"color: #000000;\">;<\/span>\r\n<span style=\"color: #AF00DB;\">export<\/span><span style=\"color: #000000;\"> <\/span><span style=\"color: #0000FF;\">const<\/span><span style=\"color: #000000;\"> <\/span><span style=\"color: #0070C1;\">el<\/span><span style=\"color: #000000;\"> = <\/span><span style=\"color: #795E26;\">_jsx<\/span><span style=\"color: #000000;\">(<\/span><span style=\"color: #A31515;\">&quot;div&quot;<\/span><span style=\"color: #000000;\">, { <\/span><span style=\"color: #001080;\">children:<\/span><span style=\"color: #000000;\"> <\/span><span style=\"color: #A31515;\">&quot;foo&quot;<\/span><span style=\"color: #000000;\"> }, <\/span><span style=\"color: #0000FF;\">void<\/span><span style=\"color: #000000;\"> <\/span><span style=\"color: #098658;\">0<\/span><span style=\"color: #000000;\">);<\/span>\r\n<\/code><\/pre>\n<p>That last <code>void 0<\/code> argument is unnecessary in this emit mode, and removing it can improve bundle sizes.<\/p>\n<pre class=\"lang:default decode:true\" style=\"background-color: #f0f0f0;padding: 10px;border-radius: 10px;\"><code><span style=\"color: #A31515;\">- export const el = _jsx(&quot;div&quot;, { children: &quot;foo&quot; }, void 0);<\/span>\r\n<span style=\"color: #098658;\">+ export const el = _jsx(&quot;div&quot;, { children: &quot;foo&quot; });<\/span>\r\n<\/code><\/pre>\n<p>Thanks to <a href=\"https:\/\/github.com\/microsoft\/TypeScript\/pull\/47467\">a pull request<\/a> from <a href=\"https:\/\/github.com\/a-tarasyuk\">Alexander Tarasyuk<\/a>, TypeScript 4.6 now drops the <code>void 0<\/code> argument.<\/p>\n<h2><a name=\"jsdoc-name-suggestions\"><\/a> JSDoc Name Suggestions<\/h2>\n<p>In JSDoc, you can document parameters using an <code>@param<\/code> tag.<\/p>\n<pre class=\"lang:default decode:true\" style=\"background-color: #f0f0f0;padding: 10px;border-radius: 10px;\"><code><span style=\"color: #008000;\">\/**<\/span>\r\n<span style=\"color: #008000;\"> * <\/span><span style=\"color: #0000FF;\">@param<\/span><span style=\"color: #008000;\"> <\/span><span style=\"color: #001080;\">x<\/span><span style=\"color: #008000;\"> The first operand<\/span>\r\n<span style=\"color: #008000;\"> * <\/span><span style=\"color: #0000FF;\">@param<\/span><span style=\"color: #008000;\"> <\/span><span style=\"color: #001080;\">y<\/span><span style=\"color: #008000;\"> The second operand<\/span>\r\n<span style=\"color: #008000;\"> *\/<\/span>\r\n<span style=\"color: #0000FF;\">function<\/span><span style=\"color: #000000;\"> <\/span><span style=\"color: #795E26;\">add<\/span><span style=\"color: #000000;\">(<\/span><span style=\"color: #001080;\">x<\/span><span style=\"color: #000000;\">, <\/span><span style=\"color: #001080;\">y<\/span><span style=\"color: #000000;\">) {<\/span>\r\n<span style=\"color: #000000;\">    <\/span><span style=\"color: #AF00DB;\">return<\/span><span style=\"color: #000000;\"> <\/span><span style=\"color: #001080;\">x<\/span><span style=\"color: #000000;\"> + <\/span><span style=\"color: #001080;\">y<\/span><span style=\"color: #000000;\">;<\/span>\r\n<span style=\"color: #000000;\">}<\/span>\r\n<\/code><\/pre>\n<p>But what happens when these comments fall out of date?\nWhat if we rename <code>x<\/code> and <code>y<\/code> to <code>a<\/code> and <code>b<\/code>?<\/p>\n<pre class=\"lang:default decode:true\" style=\"background-color: #f0f0f0;padding: 10px;border-radius: 10px;\"><code><span style=\"color: #008000;\">\/**<\/span>\r\n<span style=\"color: #008000;\"> * <\/span><span style=\"color: #0000FF;\">@param<\/span><span style=\"color: #008000;\"> <\/span><span style=\"color: #001080;\">x<\/span><span style=\"color: #008000;\"> {number} The first operand<\/span>\r\n<span style=\"color: #008000;\"> * <\/span><span style=\"color: #0000FF;\">@param<\/span><span style=\"color: #008000;\"> <\/span><span style=\"color: #001080;\">y<\/span><span style=\"color: #008000;\"> {number} The second operand<\/span>\r\n<span style=\"color: #008000;\"> *\/<\/span>\r\n<span style=\"color: #0000FF;\">function<\/span><span style=\"color: #000000;\"> <\/span><span style=\"color: #795E26;\">add<\/span><span style=\"color: #000000;\">(<\/span><span style=\"color: #001080;\">a<\/span><span style=\"color: #000000;\">, <\/span><span style=\"color: #001080;\">b<\/span><span style=\"color: #000000;\">) {<\/span>\r\n<span style=\"color: #000000;\">    <\/span><span style=\"color: #AF00DB;\">return<\/span><span style=\"color: #000000;\"> <\/span><span style=\"color: #001080;\">a<\/span><span style=\"color: #000000;\"> + <\/span><span style=\"color: #001080;\">b<\/span><span style=\"color: #000000;\">;<\/span>\r\n<span style=\"color: #000000;\">}<\/span>\r\n<\/code><\/pre>\n<p>Previously TypeScript would only tell you about this when performing type-checking on JavaScript files &#8211; when using either the <code>checkJs<\/code> option, or adding a <code>\/\/ @ts-check<\/code> comment to the top of your file.<\/p>\n<p>You can now get similar information for TypeScript files in your editor!\nTypeScript now provides suggestions for when parameter names don&#8217;t match between your function and its JSDoc comment.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/typescript\/wp-content\/uploads\/sites\/11\/2022\/02\/jsdoc-comment-suggestions-4-6.png\" alt=\"Suggestion diagnostics being shown in the editor for parameter names in JSDoc comments that don't match an actual parameter name.\"><\/p>\n<p><a href=\"https:\/\/github.com\/microsoft\/TypeScript\/pull\/47257\">This change<\/a> was provided courtesy of <a href=\"https:\/\/github.com\/a-tarasyuk\">Alexander Tarasyuk<\/a>!<\/p>\n<h2><a name=\"syntax-errors-js\"><\/a> More Syntax and Binding Errors in JavaScript<\/h2>\n<p>TypeScript has expanded its set of syntax and binding errors in JavaScript files.\nYou&#8217;ll see these new errors if you open JavaScript files in an editor like Visual Studio or Visual Studio Code, or if you run JavaScript code through the TypeScript compiler &#8211; even if you don&#8217;t turn on <code>checkJs<\/code> or add a <code>\/\/ @ts-check<\/code> comment to the top of your files.<\/p>\n<p>As one example, if you have two declarations of a <code>const<\/code> in the same scope of a JavaScript file, TypeScript will now issue an error on those declarations.<\/p>\n<pre class=\"lang:default decode:true\" style=\"background-color: #f0f0f0;padding: 10px;border-radius: 10px;\"><code><span style=\"color: #0000FF;\">const<\/span><span style=\"color: #000000;\"> <\/span><span style=\"color: #0070C1;\">foo<\/span><span style=\"color: #000000;\"> = <\/span><span style=\"color: #098658;\">1234<\/span><span style=\"color: #000000;\">;<\/span>\r\n<span style=\"color: #008000;\">\/\/    ~~~<\/span>\r\n<span style=\"color: #008000;\">\/\/ error: Cannot redeclare block-scoped variable 'foo'.<\/span>\r\n\r\n<span style=\"color: #008000;\">\/\/ ...<\/span>\r\n\r\n<span style=\"color: #0000FF;\">const<\/span><span style=\"color: #000000;\"> <\/span><span style=\"color: #0070C1;\">foo<\/span><span style=\"color: #000000;\"> = <\/span><span style=\"color: #098658;\">5678<\/span><span style=\"color: #000000;\">;<\/span>\r\n<span style=\"color: #008000;\">\/\/    ~~~<\/span>\r\n<span style=\"color: #008000;\">\/\/ error: Cannot redeclare block-scoped variable 'foo'.<\/span>\r\n<\/code><\/pre>\n<p>As another example, TypeScript will let you know if a modifier is being incorrectly used.<\/p>\n<pre class=\"lang:default decode:true\" style=\"background-color: #f0f0f0;padding: 10px;border-radius: 10px;\"><code><span style=\"color: #0000FF;\">function<\/span><span style=\"color: #000000;\"> <\/span><span style=\"color: #795E26;\">container<\/span><span style=\"color: #000000;\">() {<\/span>\r\n<span style=\"color: #000000;\">    <\/span><span style=\"color: #AF00DB;\">export<\/span><span style=\"color: #000000;\"> <\/span><span style=\"color: #0000FF;\">function<\/span><span style=\"color: #000000;\"> <\/span><span style=\"color: #795E26;\">foo<\/span><span style=\"color: #000000;\">() {<\/span>\r\n<span style=\"color: #008000;\">\/\/  ~~~~~~<\/span>\r\n<span style=\"color: #008000;\">\/\/ error: Modifiers cannot appear here.<\/span>\r\n\r\n<span style=\"color: #000000;\">    }<\/span>\r\n<span style=\"color: #000000;\">}<\/span>\r\n<\/code><\/pre>\n<p>These errors can be disabled by adding a <code>\/\/ @ts-nocheck<\/code> at the top of your file, but we&#8217;re interested in hearing some early feedback about how it works for your JavaScript workflow.\nYou can easily try it out for Visual Studio Code by installing the <a href=\"https:\/\/marketplace.visualstudio.com\/items?itemName=ms-vscode.vscode-typescript-next\">TypeScript and JavaScript Nightly Extension<\/a>, and read up more on the <a href=\"https:\/\/github.com\/microsoft\/TypeScript\/pull\/47067\">first<\/a> and <a href=\"https:\/\/github.com\/microsoft\/TypeScript\/pull\/47075\">second<\/a> pull requests.<\/p>\n<h2><a name=\"typescript-trace-analyzer\"><\/a> TypeScript Trace Analyzer<\/h2>\n<p>Occasionally, teams may encounter types that are computationally expensive to create and compare against other types.\n<a href=\"https:\/\/github.com\/microsoft\/TypeScript\/wiki\/Performance#performance-tracing\">TypeScript has a <code>--generateTrace<\/code> flag<\/a> to help identify some of those expensive types, or sometimes help diagnose issues in the TypeScript compiler.\nWhile the information generated by <code>--generateTrace<\/code> can be useful (especially with some information added in TypeScript 4.6), it can often be hard to read in existing trace visualizers.<\/p>\n<p>We recently published a tool called <a href=\"https:\/\/www.npmjs.com\/package\/@typescript\/analyze-trace\">@typescript\/analyze-trace<\/a> to get a more digestible view of this information.\nWhile we don&#8217;t expect everyone to need <code>analyze-trace<\/code>, we think it can come in handy for any team that is running into <a href=\"https:\/\/github.com\/microsoft\/TypeScript\/wiki\/Performance\">build performance issues with TypeScript<\/a>.<\/p>\n<p>For more information, <a href=\"https:\/\/github.com\/microsoft\/typescript-analyze-trace\">see the <code>analyze-trace<\/code> tool&#8217;s repo<\/a>.<\/p>\n<h2><a name=\"breaking-changes\"><\/a> Breaking Changes<\/h2>\n<h3>Object Rests Drop Unspreadable Members from Generic Objects<\/h3>\n<p>Object rest expressions now drop members that appear to be unspreadable on generic objects.\nIn the following example&#8230;<\/p>\n<pre class=\"lang:default decode:true\" style=\"background-color: #f0f0f0;padding: 10px;border-radius: 10px;\"><code><span style=\"color: #0000FF;\">class<\/span><span style=\"color: #000000;\"> <\/span><span style=\"color: #267F99;\">Thing<\/span><span style=\"color: #000000;\"> {<\/span>\r\n<span style=\"color: #000000;\">    <\/span><span style=\"color: #001080;\">someProperty<\/span><span style=\"color: #000000;\"> = <\/span><span style=\"color: #098658;\">42<\/span><span style=\"color: #000000;\">;<\/span>\r\n\r\n<span style=\"color: #000000;\">    <\/span><span style=\"color: #795E26;\">someMethod<\/span><span style=\"color: #000000;\">() {<\/span>\r\n<span style=\"color: #000000;\">        <\/span><span style=\"color: #008000;\">\/\/ ...<\/span>\r\n<span style=\"color: #000000;\">    }<\/span>\r\n<span style=\"color: #000000;\">}<\/span>\r\n\r\n<span style=\"color: #0000FF;\">function<\/span><span style=\"color: #000000;\"> <\/span><span style=\"color: #795E26;\">foo<\/span><span style=\"color: #000000;\">&lt;<\/span><span style=\"color: #267F99;\">T<\/span><span style=\"color: #000000;\"> <\/span><span style=\"color: #0000FF;\">extends<\/span><span style=\"color: #000000;\"> <\/span><span style=\"color: #267F99;\">Thing<\/span><span style=\"color: #000000;\">&gt;(<\/span><span style=\"color: #001080;\">x<\/span><span style=\"color: #000000;\">: <\/span><span style=\"color: #267F99;\">T<\/span><span style=\"color: #000000;\">) {<\/span>\r\n<span style=\"color: #000000;\">    <\/span><span style=\"color: #0000FF;\">let<\/span><span style=\"color: #000000;\"> { <\/span><span style=\"color: #001080;\">someProperty<\/span><span style=\"color: #000000;\">, ...<\/span><span style=\"color: #001080;\">rest<\/span><span style=\"color: #000000;\"> } = <\/span><span style=\"color: #001080;\">x<\/span><span style=\"color: #000000;\">;<\/span>\r\n\r\n<span style=\"color: #000000;\">    <\/span><span style=\"color: #008000;\">\/\/ Used to work, is now an error!<\/span>\r\n<span style=\"color: #000000;\">    <\/span><span style=\"color: #008000;\">\/\/ Property 'someMethod' does not exist on type 'Omit&lt;T, &quot;someProperty&quot; | &quot;someMethod&quot;&gt;'.<\/span>\r\n<span style=\"color: #000000;\">    <\/span><span style=\"color: #001080;\">rest<\/span><span style=\"color: #000000;\">.<\/span><span style=\"color: #795E26;\">someMethod<\/span><span style=\"color: #000000;\">();<\/span>\r\n<span style=\"color: #000000;\">}<\/span>\r\n<\/code><\/pre>\n<p>the variable <code>rest<\/code> used to have the type <code>Omit&lt;T, &quot;someProperty&quot;&gt;<\/code> because TypeScript would strictly analyze which other properties were destructured.\nThis doesn&#8217;t model how <code>...rest<\/code> would work in a destructuring from a non-generic type because <code>someMethod<\/code> would typically be dropped as well.\nIn TypeScript 4.6, the type of <code>rest<\/code> is <code>Omit&lt;T, &quot;someProperty&quot; | &quot;someMethod&quot;&gt;<\/code>.<\/p>\n<p>This can also come up in cases when destructuring from <code>this<\/code>.\nWhen destructuring <code>this<\/code> using a <code>...rest<\/code> element, unspreadable and non-public members are now dropped, which is consistent with destructuring instances of a class in other places.<\/p>\n<pre class=\"lang:default decode:true\" style=\"background-color: #f0f0f0;padding: 10px;border-radius: 10px;\"><code><span style=\"color: #0000FF;\">class<\/span><span style=\"color: #000000;\"> <\/span><span style=\"color: #267F99;\">Thing<\/span><span style=\"color: #000000;\"> {<\/span>\r\n<span style=\"color: #000000;\">    <\/span><span style=\"color: #001080;\">someProperty<\/span><span style=\"color: #000000;\"> = <\/span><span style=\"color: #098658;\">42<\/span><span style=\"color: #000000;\">;<\/span>\r\n\r\n<span style=\"color: #000000;\">    <\/span><span style=\"color: #795E26;\">someMethod<\/span><span style=\"color: #000000;\">() {<\/span>\r\n<span style=\"color: #000000;\">        <\/span><span style=\"color: #008000;\">\/\/ ...<\/span>\r\n<span style=\"color: #000000;\">    }<\/span>\r\n\r\n<span style=\"color: #000000;\">    <\/span><span style=\"color: #795E26;\">someOtherMethod<\/span><span style=\"color: #000000;\">() {<\/span>\r\n<span style=\"color: #000000;\">        <\/span><span style=\"color: #0000FF;\">let<\/span><span style=\"color: #000000;\"> { <\/span><span style=\"color: #001080;\">someProperty<\/span><span style=\"color: #000000;\">, ...<\/span><span style=\"color: #001080;\">rest<\/span><span style=\"color: #000000;\"> } = <\/span><span style=\"color: #0000FF;\">this<\/span><span style=\"color: #000000;\">;<\/span>\r\n\r\n<span style=\"color: #000000;\">        <\/span><span style=\"color: #008000;\">\/\/ Used to work, is now an error!<\/span>\r\n<span style=\"color: #000000;\">        <\/span><span style=\"color: #008000;\">\/\/ Property 'someMethod' does not exist on type 'Omit&lt;T, &quot;someProperty&quot; | &quot;someMethod&quot;&gt;'.<\/span>\r\n<span style=\"color: #000000;\">        <\/span><span style=\"color: #001080;\">rest<\/span><span style=\"color: #000000;\">.<\/span><span style=\"color: #795E26;\">someMethod<\/span><span style=\"color: #000000;\">();<\/span>\r\n<span style=\"color: #000000;\">    }<\/span>\r\n<span style=\"color: #000000;\">}<\/span>\r\n<\/code><\/pre>\n<p>For more details, <a href=\"https:\/\/github.com\/microsoft\/TypeScript\/pull\/47078\">see the corresponding change here<\/a>.<\/p>\n<h3>JavaScript Files Always Receive Grammar and Binding Errors<\/h3>\n<p>Previously, TypeScript would ignore most grammar errors in JavaScript apart from accidentally using TypeScript syntax in a JavaScript file.\nTypeScript now shows JavaScript syntax and binding errors in your file, such as using incorrect modifiers, duplicate declarations, and more.\nThese will typically be most apparent in Visual Studio Code or Visual Studio, but can also occur when running JavaScript code through the TypeScript compiler.<\/p>\n<p>You can explicitly turn these errors off by inserting a <code>\/\/ @ts-nocheck<\/code> comment at the top of your file.<\/p>\n<p>For more information, see the <a href=\"https:\/\/github.com\/microsoft\/TypeScript\/pull\/47067\">first<\/a> and <a href=\"https:\/\/github.com\/microsoft\/TypeScript\/pull\/47075\">second<\/a> implementing pull requests for these features.<\/p>\n<h2>What&#8217;s Next?<\/h2>\n<p>We hope that this release of TypeScript makes coding a joy.\nIf you&#8217;re excited to hear about what we have in mind for our next release, you can head over to our issue tracker and <a href=\"https:\/\/github.com\/microsoft\/TypeScript\/issues\/48027\">read up on our iteration plan for TypeScript 4.7<\/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 announcing the availability of TypeScript 4.6. If you&#8217;re not yet familiar with TypeScript, it&#8217;s a language that builds on JavaScript and adds syntax for types. Types help describe what kinds of values you&#8217;re working with and what kinds of functions you&#8217;re calling. TypeScript can use this information to help you avoid about mistakes [&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-3286","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-typescript"],"acf":[],"blog_post_summary":"<p>Today we&#8217;re announcing the availability of TypeScript 4.6. If you&#8217;re not yet familiar with TypeScript, it&#8217;s a language that builds on JavaScript and adds syntax for types. Types help describe what kinds of values you&#8217;re working with and what kinds of functions you&#8217;re calling. TypeScript can use this information to help you avoid about mistakes [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/typescript\/wp-json\/wp\/v2\/posts\/3286","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=3286"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/typescript\/wp-json\/wp\/v2\/posts\/3286\/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=3286"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/typescript\/wp-json\/wp\/v2\/categories?post=3286"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/typescript\/wp-json\/wp\/v2\/tags?post=3286"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}