Whether you are using Typescript in 2020 or not, there is one undeniable fact and that is that the language is growing steadily and evolving fast, bringing more convenience and solid ground for our apps to grow and scale, without having to sacrifice from their maintainability. At the time this article is written the language has 12,125,535 weekly downloads from npmjs.com. To give you some perspective over those numbers React has 7,671,193 weekly downloads.

Moreover the yearly survey of Stack Overflow about the most beloved languages shows that this year Typescript grows up with one position, replacing Python and taking over the silver medal, giving way only to Rust in this category. Again for comparison purposes in the same survey JavaScript takes the 10th position this year.

I hope that if you are still wondering if you should go and dig deeper into Typescript, these few lines already convinced you into it.

Enough small talk, let me give you an overview of what you can expect from this article:

  • What is new and upcoming in the language.
  • A few examples of helpful patterns and utilities from the recent past, that might not be that well known but sure enough, very handy.

Let’s get started, what is new in Typescript?

Lately, there is a lot going on in the Typescript land. Just a few days back the Typescript homepage got a new fresher look with more extensive and better-structured documentation, updated TS playground, as well as (my favourite part) dedicated section for all the flags that you can use in your tsconfig file with detailed explanation and examples reference you can find here.

If you are using Typescript, I would strongly recommend to take a few minutes and get yourself familiar with the new website. If you are thinking about whether or not to start out with the language that is an even better reason to take a quick look at the docs.

Apart from the polished website, the release candidate of version 4.0 was announced as well. The full list of new features and additions you can find here. I will try to cover the most interesting parts of it in the next few lines.

Tuples no longer have to be weird and cumbersome to type

Tuples can be represented with a generic element that can now be spread and this is way more convenient to type because we no longer need to know the actual type structure in advance.

This will be a valid syntax:

const returnTuple = (arg: Array<unknown>):[string, ...T]

Moreover, we can now spread elements and place them anywhere in the tuple for example:

const returnTuple = (arg: Array<unknown>):[...T, string, ...R]

or in other words the element to spread doesn’t have to be in the last position anymore. Before this addition, if we tried to spread an element that was not last in the tuple, we would see this compile error message

#technology #software-development #typescript #programming #javascript

What to expect from Typescript 4.0 and more.
1.55 GEEK