Annotated solution
Published August 19, 2026The solution
type PickByType<T, U> = { [K in keyof T as T[K] extends U ? K : never]: T[K] }
The common wrong answer
type PickByType<T, U> = { [K in keyof T]: T[K] extends U ? T[K] : never }
The filtering happens on the value side, so every key survives — the rejected ones just hold never. PickByType<Mixed, number> becomes { id: number; name: never; active: never; score: number }, which is a very different type from the one asked for, and a nearly unusable one.
Line by line
as T[K] extends U ? K : neverThe
asclause rewrites each key as the mapping runs. Here the rewrite is conditional: keep the key unchanged when the value matches, or rename it toneverwhen it does not.neverA key of type
nevercannot exist, so TypeScript omits the property rather than creating an impossible one. That quiet rule is what turns key remapping into a filter.
Takeaway
Filtering an object type happens in the key clause, never in the value. as ... : never is the only way to make a property genuinely disappear.

