← Back to Gists

Pick and omit

📝 TypeScript
jeffrey75962
jeffrey75962 · 20d ago
This TypeScript snippet demonstrates how to use Pick and Omit utility types to create new types by selecting or excluding specific properties from an existing type.
TypeScript
type Person = { name: string; age: number; email: string;
}; type NameAge = Pick<Person, 'name' | 'age'>;
type ContactOnly = Omit<Person, 'age'>; const person: NameAge = { name: 'Alice', age: 30 };
const contact: ContactOnly = { name: 'Bob', email: 'bob@example.com' };

Comments

No comments yet. Start the discussion.