TypeScript 4.0 comes with lots of new features to make JavaScript development easier.

In this article, we’ll look at the best features of TypeScript 4.

  • Variadic Tuples
  • Labeled Tuple Elements
  • Class Property Inference from Constructors
  • Short-Circuiting Assignment Operators
  • unknown on catch Clause Bindings

Variadic Tuples

TypeScript 4.0 comes with data types for tuples with a variable number of elements.

We can use the spread operator to create a type with the elements we want in our tuple.

For example, we write:

type Strings = [string, string];
type Numbers = number[];

type Unbounded = [...Strings, ...Numbers, boolean];

to create an Unbounded data type to add a tuple type with strings, numbers, and booleans.

The inference process is also automatic so that if we have 2 strings, numbers, and a boolean in the same order, TypeScript will infer the tuple as having the Unbounded type.

#typescript #javascript #web-development #programming #developer

What’s New in TypeScript 4.0?
2.30 GEEK