Annotated solution
Published September 11, 2026The solution
type OptionalKeys<T> = { [K in keyof T]-?: {} extends Pick<T, K> ? K : never }[keyof T]
The common wrong answer
type OptionalKeys<T> = { [K in keyof T]: {} extends Pick<T, K> ? K : never }[keyof T]
The detection is right and the answer still comes out wrong: `"b" | undefined` instead of `"b"`. Without `-?`, the mapping copies the optionality of each key onto its own result, so the very keys you are trying to collect are optional in your lookup table — and indexing an optional property adds `undefined` to what you get back.
Line by line
{} extends Pick<T, K>An object with one required property cannot accept `{}`; one with a single optional property can. That asymmetry is the whole test.
-?Strip optionality from the table you are building. You are storing answers, not mirroring the input, and an answer that might be missing is not an answer.
[keyof T]Indexing by every key at once collapses the table into a union, and the `never` entries vanish on their own — `never` in a union is nothing at all.
Takeaway
When a mapped type is a lookup table rather than a transformed copy, `-?` belongs on it. Inherited modifiers are for rebuilding an object; they only get in the way when you are computing an answer.

