With 65k stars on Github on the time of writing this post, you can easily conclude that the language has found its way into developers toolbelt when developing javascript based applications. According to the annual developer survey from Stack Overflow (survey can be found  here) Typescript is the second most loved language with a rating of 67.1% where Javascript is on the 10th place with 58.3%.

I often hear from people working with vanilla javascript on a daily basis that they are curious on Typescript and what it provides, but is also restrained by the assumption that they will loose some of the flexibility that plain javascript provides.

You might also be a developer who just have focused on developing new features and keep creating new interfaces and classes with just a slight different in naming every time a new data model has appeared or you keep making the properties optional or of type any to make typescript compiler stop complaining when writing code.

If you ever find yourself in one of the situations above, or is just curious about how you can improve your typescript skills with Utility types, you have come to the right place.

What is Typescript Utility Types

Utility Types is special types shipped with the Typescript language and can be used to improve the readability and flexibility of the language while reducing the boilerplate code.

To simply put it, you provide a value and the utility types will construct a new type under the constraint that the specific utility type has defined.

interface Todo {
  title: string;
  description: string;
  completed: boolean;
}

type TodoPreview = Readonly<Todo>;

const todo: TodoPreview = {
  title: "Clean room",
  description: "Clean room and floor",
  completed: false,
};

todo.title = "Clean room again";

#javascript #typescript #advanced-types

Take Your Typescript Skills to The Next Level with Utility Types
1.80 GEEK