Select Fields with Pick and Omit
Write a TypeScript function that uses Pick
The Pick
These utility types are part of TypeScript's mapped types family. They operate entirely at the type level and are erased at runtime. They enable expressing complex type transformations concisely without manual interface duplication.
Time complexity is O(n) for the runtime property access. Space complexity is O(k) for the new object. The Pick type itself has zero runtime overhead as it's a compile-time construct.
Edge cases include picking a single key, omitting all keys (results in empty object type), and ensuring the keys provided to Pick are valid keys of the original type (enforced by the K extends keyof T constraint).
Example Input & Output
Default pick
Pick name and age
Minimal profile
Another user
Another profile
Algorithm Flow

Solution Approach
Best Answers
interface User {
id: number;
name: string;
age: number;
email: string;
}
type PublicProfile = Pick<User, 'name' | 'age'>;
function solution(user: User): PublicProfile {
return { name: user.name, age: user.age };
}Comments (0)
Join the Discussion
Share your thoughts, ask questions, or help others with this Challenge.
