Let’s explore the latest version of TypeScript

TypeScript has announced its latest version of TypeScript today (20th of August, 2020) and I thought of doing a quick recap on its features and changes. With this release, TypeScript brings the final, stable version of their latest update. Although this brings a new major version, there are no more substantially large, breaking changes than usual. So let’s see what’s new in this version.

Labeled Tuple Elements

This language feature changes the way a tuple is defined. Previously, tuples were defined as follows:

function tuple(...args: [string, number]): void {
    // ...
}

In the above example, there are no parameter names for the first and second elements. While these have no impact on type-checking, the lack of labels on tuple positions can make them harder to use — harder to communicate our intent.

As a solution to this, TypeScrip 4.0 brings tuples with labels.

type Segment = [length: number, count: number];

But if you are going to label an element, you must label all the elements in the tuple. If not, you will receive an error.

type Segment = [first: string, number];
//                         ~~~~~~
// error! Tuple members must all have names or all not have names.

#javascript #typescript #web-development #developer

What’s New in TypeScript 4.0
1.65 GEEK