Pick
Pick
allows us to create a new type by selecting a set of properties from an existing type.- It’s useful when you want a type that only contains a subset of the properties of another type.
interface User { id: string; name: string; age: number; email: string; password: string;}
// Create a type for displaying a user profiletype UserProfile = Pick<User, 'name' | 'email'>;
const displayUserProfile = (user: UserProfile) => { console.log(`Name: ${user.name}, Email: ${user.email}`);};
const user: UserProfile = { name: 'John Doe', email: 'john@example.com' };displayUserProfile(user); // Output: Name: John Doe, Email: john@example.com