Annotated solution
Published August 31, 2026The solution
type OmitByType<T, U> = { [K in keyof T as T[K] extends U ? never : K]: T[K] }The common wrong answer
type OmitByType<T, U> = { [K in keyof T]: T[K] extends U ? never : T[K] }This filters the value and leaves the key standing. a is still there, now typed never — a property nobody can ever supply a value for, which is not the same thing as a property that does not exist. Filtering on the value side can empty a key; it cannot delete one.
Line by line
as T[K] extends U ? never : KThe
asclause renames the key being produced. Renaming it toneveris the one way to make a mapped type emit no property at all for that iteration.OmitByType<{ a: 1; b: 2 }, never>Nothing is dropped here, because
1 extends neveris false.neveris the empty set: no type is assignable to it, so no key matches and everything survives.
Takeaway
Keys are removed in the key clause, never in the value clause. If you find yourself producing never as a property type, you almost certainly meant to produce no property.

