<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: heypran</title>
    <description>The latest articles on Forem by heypran (@heypran).</description>
    <link>https://forem.com/heypran</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F397451%2F7c24e855-b6fe-4276-be8b-bd36be5509b6.png</url>
      <title>Forem: heypran</title>
      <link>https://forem.com/heypran</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/heypran"/>
    <language>en</language>
    <item>
      <title>Typescript 3.9: What got changed?</title>
      <dc:creator>heypran</dc:creator>
      <pubDate>Thu, 28 May 2020 20:48:19 +0000</pubDate>
      <link>https://forem.com/heypran/typescript-3-9-what-got-changed-3jc5</link>
      <guid>https://forem.com/heypran/typescript-3-9-what-got-changed-3jc5</guid>
      <description>&lt;p&gt;Hey! guys, in this post I will be discussing the changes brought in by typescript 3.9. I will give some code examples and brief descriptions.&lt;/p&gt;

&lt;h2&gt;
  
  
  Breaking Changes
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Parsing differences in optional chaining &amp;amp; non-Null assertions
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Previous versions: In some cases, using optional chaining (?) with non-null assertions (!) alters the behavior of short-circuiting (optional chaining no longer works). &lt;/li&gt;
&lt;li&gt;&lt;p&gt;Now (3.9): The above no longer happens and code is intuitive. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Below code demonstrates this&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { ec } from 'easy-console';

interface Orders {
  orderDetail?: OrderDetail; // orderDetail: OrderDetail | undefined;
}

interface OrderDetail {
  item?: Item; // item: Item | undefined;
}

interface Item {
  price: number;
}

const order: Orders = { orderDetail: undefined };


const itemPrice: number = order.orderDetail?.item!.price; //

// Before
ec.l(itemPrice); // trying to access property on undefined

// v3.9
ec.l(itemPrice); //undefined
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h3&gt;
  
  
  Stricter checks on intersections and optional properties
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Previous versions: Types derived by using intersection can be assigned to other similar types without stricter checks on the underneath type properties.&lt;/li&gt;
&lt;li&gt;Now: There are stricter checks on the types when using the intersection types. So it will not work if the types are exactly not same.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { ec } from 'easy-console';

interface A {
  a: number; // notice this is 'number'
}

interface B {
  b: string;
}

interface C {
  a?: boolean; // notice this is 'boolean'
  b: string;
}

const x: A &amp;amp; B = { a: 1, b: `s` };

// Before
const y: C = x; // Type 'number' is not assignable to type 'boolean'.

ec.l(`x&amp;gt;&amp;gt;`, x); // { a: 1, b: `s` }
ec.l(`y&amp;gt;&amp;gt;`, y); // { a: 1, b: `s` }

// 3.9
const y: C = x; // error-  Type 'number' is not assignable to type 'boolean'.
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h3&gt;
  
  
  Stricter check on Intersections derived from different type properties
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Before: Intersection of types which have same properties with no overlapping type, collapses to never for that particular particular property.&lt;/li&gt;
&lt;li&gt;Now: Intersection of types which have same properties with nothing in common, collapses the whole intersection type to never.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { ec } from 'easy-console';

interface Category {
  iam: 'categoryType';
  categoryName: string;
  level: number;
}

interface Product {
  iam: 'productType';
  productName: string;
  productPrice: number;
}

type Group = Category &amp;amp; Product; // 3.9 whole types becomes never

const group: Group = {
  categoryName: 'Laptops',
  level: 1,
  productName: 'Macbook',
  productPrice: 1234,
  iAm: "never say never",  // in previous version only the particular type becomes
};

// Before
ec.l('group.iAm =&amp;gt;', group); // previous version - error only on 'iAm' property

// 3.9
ec.l('group.iAm =&amp;gt;', group); // version 3.9 - error on all properties

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h3&gt;
  
  
  '}' and '&amp;gt;' are Now Invalid JSX Text Characters
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Now you cannot use them directly in .tsx files. You will get below errors.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Unexpected token. Did you mean `{'&amp;gt;'}` or `&amp;amp;gt;`?
Unexpected token. Did you mean `{'}'}` or `&amp;amp;rbrace;`?
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h3&gt;
  
  
  Type Parameters That Extend any No Longer Act as any
&lt;/h3&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { ec } from 'easy-console';

function foo&amp;lt;T extends any&amp;gt;(arg: T) {
  ec.l('arg.anyArguments', arg.IwillNotGiveError); // previous versions no error 
}

function foo&amp;lt;T extends any&amp;gt;(arg: T) {
  ec.l('arg.anyArguments', arg.IwillGiveError); // 3.9 error 
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h2&gt;
  
  
  Improvements
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Improvements in Inference and Promise.all
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;In certain cases when while using Promise.all(), the response types of the promises get mismatched in the result. This results in compile time error. This was observed mostly when an undefined type was present. Find below the codebox ( on older version).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;iframe src="https://codesandbox.io/embed/qjx5f"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;h3&gt;
  
  
  // @ts-expect-error Comments
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;It allows you to accept an error where there is a type error. For eg. In a scenario where you are writing a test, and you deliberately want to pass different types of values.&lt;/li&gt;
&lt;li&gt;How is it different from @ts-ignore ?&lt;/li&gt;
&lt;li&gt;@ts-expect-error will notify you when it is not required.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;describe('Todo', () =&amp;gt; {

  it('sample test', () =&amp;gt; {
    function expectErr(a: string) {
      expect(a).toBe('string');
    }

    // @ts-expect-error
    expectErr(1);    // no error

    // @ts-expect-error
    expectErr("a");  // error

  });
});
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h3&gt;
  
  
  Uncalled Function Checks in Conditional Expressions (?:)
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;In previous versions, typescript was doing a check, whether we have called our functions while using conditions (such as if else) or not. But not on the using the conditional operators (? :). But now it supports the same.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function hasImportantPermissions(): boolean {
    // ...
}

// Oops!
if (hasImportantPermissions) {
//  ~~~~~~~~~~~~~~~~~~~~~~~
// This condition will always return true since the function is always defined.
// Did you mean to call it instead?
    deleteAllTheImportantFiles();
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h3&gt;
  
  
  Typescript now support "solution style" tsconfig.json files
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;You can define the several tsconfig in one file, rather than placing in individual directory structure.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// tsconfig.json
{
    "files": [],
    "references": [
        { "path": "./tsconfig.shared.json" },
        { "path": "./tsconfig.frontend.json" },
        { "path": "./tsconfig.backend.json" },
    ]
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h3&gt;
  
  
  Other improvements
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;CommonJS auto-imports imports like JS (using require statement )&lt;/li&gt;
&lt;li&gt;Compile time improvements&lt;/li&gt;
&lt;li&gt;Editor improvements- improved support for sublime, vscode, nightly&lt;/li&gt;
&lt;li&gt;Editor Code Actions- properly preserve spacing/line breaks&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For more detailed information and issue specific pull request, refer the following link:&lt;br&gt;
&lt;a href="https://devblogs.microsoft.com/typescript/announcing-typescript-3-9-beta/"&gt;https://devblogs.microsoft.com/typescript/announcing-typescript-3-9-beta/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Happy Hacking!&lt;/p&gt;

</description>
      <category>typescript</category>
      <category>javascript</category>
      <category>news</category>
    </item>
  </channel>
</rss>
