Utility Types
Partial<T>
// Define the original full type
interface User {
id: string;
name: string;
age: number;
}
// Use Partial to make all fields optional
type UpdateUser = Partial<User>;
// You can now create an object with just some fields
const updatedUserInfo: UpdateUser = {
name: "Bob", // no need for id or age
};
// Simulate an update function where not all user data needs to change
const updateUser = (user: UpdateUser): void => {
// This function accepts any subset of the User fields
console.log("Updating user with:", user);
};
updateUser(updatedUserInfo); // Updating user with: { name: "Bob" }Required<T>
Pick<T, K>
Omit<T, K>
Record<K, T>
Exclude<T, U>
Extract<T, U>
NonNullable<T>
ReturnType<T>
Last updated