Common Utility Types of TypeScript

Author
Khalid Khan
Learn about the TypeScript Utility Types How they modify other types and make life easior for generate the other types.

Hello TypeScripters 😊
In this artical you will learn basic and common Typescript Utility types such as Partial<T> Required<T> Pick<T, K> and more. 🔥
##1. Partial<T> – Make All Properties Optional 🤢
The Partial<T> utility type takes a type T and makes all its properties optional. This is useful when updating objects where only a subset of properties may be provided.
codecode
##2. Required<T> – Make All Properties Required 🤷♂️
The Required<T> utility type does the opposite of Partial<T> by ensuring that all properties of T are required.
codecode
##3. Readonly<T> – Make All Properties Read-Only 👏
The Readonly<T> utility type prevents properties from being modified after initialization.
code
##4. Pick<T, K> – Select Specific Properties 😁
The Pick<T, K> utility type extracts a subset of properties from T.
codecode
##5. Omit<T, K> – Remove Specific Properties 😉
The Omit<T, K> utility type removes specified properties from T.
codecode
##6. Record<K, T> – Define a Key-Value Object Type 🙌
The Record<K, T> utility type creates an object type where keys are K and values are T.
type Role = "admin" | "user" | "guest";code
##7. Extract<T, U> – Extract Common Types 🤞
The Extract<T, U> utility type extracts types from T that are also present in U.
code
##8. Exclude<T, U> – Remove Certain Types 🤔
The Exclude<T, U> utility type removes types from T that match U.
code
Happy Types 😍😍🎉
