Understanding the weird parts of Typescript

Moshe Kerbel

Aug 10 · 7 min read

Image for post

Generics <T>

Let’s take a look at the following example — A reusable table component.

Image for post

  1. The data in the table can be sorted by clicking on the column’s title.
  2. A single row can be selected when the user clicks on it.

Image for post

Image for post

NOTE TO MENTION

In most code, you will encounter a short version of naming like T, K, V, etc’.

Next part — Utility Types

This part talks about Partial, Pick, and Omit which are part of the utility types that Typescript supply. These types help us make types’ transformations. The official typescript docs contain a short and solid doc about it.

Image for post

Last subject — Event handlers

Another piece of code that looks weird at first is where we use existing types for event handlers.

Image for post


Last words

The code examples in the post were reduced for better clarity of the idea I tried to convey. Longer and more precise versions of all code examples can be found here.

Author: admin

Leave a Reply

Your email address will not be published.