Complete worked example
typescript
function requireId<T extends { id: string }>(value: T): T {
if (!value.id) throw new Error("Missing id");
return value;
}
const record = { id: "a", salary: 10 };
const same = requireId(record);- Reasoning
- The original object satisfies the constraint and retains its caller-specific properties.