Complete worked example
typescript
function update<T, K extends keyof T>(value: T, key: K, next: T[K]): T {
return { ...value, [key]: next };
}
const changed = update({ count: 1, title: "QA" }, "count", 2);- Reasoning
- K and T[K] connect the selected property with its replacement type.