You now have several ways to connect API shapes without repeating their fields. This practice set mixes generic lookups, restricted patches, mapped error dictionaries, literal event names, stable deduplication, defaults, getter names, and status unions. Each request stands on its own, so choose the smallest contract that describes it.
Read the runtime requirements before adding types. A perfectly typed function can still change zero to a default, return an inherited property, or expose the wrong order. The compiler checks protect the caller-facing relationships while hidden examples test those behaviors. You may use a different implementation from the worked examples as long as the public contracts remain usable and every result matches the stated rule. No new language feature is introduced here.
function byId<T extends {id:string}>(rows: readonly T[], id: string): T | undefined { return rows.find(row => row.id === id); }
function solve(ids: string[], weights: number[], target: string): number { const rows = ids.map((id,i)=>({id,weight:weights[i]})); return byId(rows,target)?.weight ?? -1; }
A complete implementation for the first scenario; trace its input before editing.