Pick and Omit: Selecting Properties
Create subtypes by including or excluding keys.
Welcome
Pick creates a type with only the specified properties. Omit creates a type without the specified properties. They are complementary tools for shaping object types.
Pick<T, K>
Keep only the listed keys from T.
interface User { id: number; name: string; email: string; role: string; }
type PublicUser = Pick<User, 'id' | 'name'>;
// { id: number; name: string }All lessons in this course
- Partial and Required: Toggling Optionality
- Pick and Omit: Selecting Properties
- Record: Mapping Keys to Value Types
- Readonly, Exclude, Extract, NonNullable