function modify<T extends object, K extends keyof T>(key: K, f: (old: T[K]) => T[K], struct: T): T function modifyC<K extends string, T>(key: K, f: (old: T) => T): <U extends {[P in K]: T}>(x: U) => U { return function <U extends {[P in K]: T}>(struct: U): U { const newStruct: U = Object.assign({}, struct); newStruct[key] = f(struct[key]); return newStruct; } }