Pick<T, K> tạo type chỉ với subset of properties K từ T: Pick<User, 'id' | 'name'> chỉ giữ lại id và name. Omit<T, K> là ngược lại: tạo type với tất cả properties trừ K, ví dụ Omit<User, 'password'> để không lộ mật khẩu trong response.
- Hữu ích cho DTOs, API response shaping, và form state management khi chỉ cần một phần của type.
- Mẹo: dùng Omit khi cần loại ít field, Pick khi cần giữ ít field — chọn cái nào viết ngắn hơn.
Pick<T, K> creates a type with only a subset of properties K from T: Pick<User, 'id' | 'name'> keeps only id and name. Omit<T, K> is the opposite: creates a type with all properties except K, e.g., Omit<User, 'password'> to avoid exposing the password in a response.
- Useful for DTOs, API response shaping, and form state management when only part of a type is needed.
- Tip: use Omit when excluding few fields, Pick when keeping few fields — choose whichever is shorter to write.