Describe how to use the 'Pick' and 'Omit' utility types in TypeScript with an example.

Instruction: Explain the purpose of 'Pick' and 'Omit' utility types and demonstrate their usage with a practical example.

Context: This question tests the candidate's knowledge of TypeScript's utility types, specifically 'Pick' and 'Omit', and their ability to manipulate types for creating more specific type definitions.

Updated

Official answer available

Read the opening below, then unlock the full answer and practical guidance.

Pick selects named properties from a type; Omit constructs a type without selected keys. These are compile-time transformations. They do not remove properties from a JavaScript object or sanitize a response.

```typescript type User = { id: string; name: string; email: string; isAdmin: boolean }; type Contact = Pick; type PublicUser = Omit; const user: User = { id: "u1", name: "Ada", email: "[email protected]",...

Related Questions