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 ๐๐๐
