Advanced TypeScript for Harness Builders
6. Distributive Conditional Types
Naked type parameters distribute over unions — critical for Omit on discriminated unions.
When T is a naked type parameter, conditional types distribute over unions. This is critical for Omit on union types.
File: packages/coding-agent/src/modes/rpc/rpc-client.ts L21-24
/** Distributive Omit that works with union types */
type DistributiveOmit<T, K extends keyof T> = T extends unknown ? Omit<T, K> : never;
/** RpcCommand without the id field (for internal send) */
type RpcCommandBody = DistributiveOmit<RpcCommand, "id">;
Why this matters: Standard Omit<RpcCommand, "id"> collapses the union into a single type with only shared keys. DistributiveOmit preserves each union member individually by using T extends unknown to trigger distribution.