TypeScript provides some **standard types **globally that act as utilities to convert existing types into new types with some modified behavior. These types are defined in the standard library of the TypeScript installation, hence you do not need to import them in your program. They are always available in your program and you can start using them right away.

In the Type System lesson, we learned about the keyof keyword to create a union type from the field names of an interface. Similarly, we learned typeof keyword to create an interface type from a plain object.

Similarly, these utility types appear in the type annotation which takes existing types as their input and returns an output type that we can use as a type for a value. I am going to cover important ones here, but you can follow this documentation link to know more about them.

💡 Types mentioned below are generic types. We are going to learn about generic types in the Generics lesson (coming soon). In this lesson, you will also learn how to create custom utility types on your own.


Partial and Required

The Partial<Type> utility type returns an interface by making all the fields of the Type optional. Normally, the Type here is an interface or a class (because call defines an implicit interface).

#programming #deno #typescript #javascript #nodejs

TypeScript — Utility Types
2.05 GEEK