2 min read

Today, Microsoft announced the general availability of TypeScript 3.3 RC in a blog post. This version does not contain any major or breaking changes.

Better behavior while calling union types

When there is a union type A | B, TypeScript now allows users to access all of the properties common to both A and B. For example, the intersection of members. You can get a property from a union type only if it’s known to be present in every union type. When every type has only one signature with identical parameters, things work. Such a restriction was too much and have errors in some areas. So, in TypeScript 3.3, the following code as shown in the blog will work:

type Fruit = "apple" | "orange";

type Color = "red" | "orange";

type FruitEater = (fruit: Fruit) => number;     // eats and ranks the fruit

type ColorConsumer = (color: Color) => string;  // consumes and describes the colors

declare let f: FruitEater | ColorConsumer;

f("orange"); // It works! Returns a 'number | string'.

f("apple");  // error - Argument of type '"apple"' is not assignable to parameter of type '"orange"'.

f("red");    // error - Argument of type '"red"' is not assignable to parameter of type '"orange"'.

The parameters of the above signatures are ‘intersected’ to create a new signature. When the impossible intersections are gone, what remains is “orange” & “orange” which is just “orange”. That is not to say there are no restrictions. The new behavior is active only when only one type in the union has multiple overloads and a generic signature. The forEach method will now be callable, but there may be some issues under noImplicitAny.

The –build mode’s –watch flag leverages incremental file watching as well in TypeScript 3.3. This can result in significantly faster builds with –build –watch. Reportedly, there was over 50% reduced build times.

Read next

Future of ESLint support in TypeScript

Announcing ‘TypeScript Roadmap’ for January 2019- June 2019

Introducing ReX.js v1.0.0 a companion library for RegEx written in TypeScript

Subscribe to the weekly Packt Hub newsletter. We'll send you the results of our AI Now Survey, featuring data and insights from across the tech landscape.