Type safe merge of object literals in typescript
问题 I want to merge two typescript objects (using object spread): var one = { a: 1 } var two = { a: 2, b: 3 } var m = {...one, ...two} // problem as property `a` is overwritten I want to use the type system to ensure none of the properties in the second object overwrite any properties in the first. I am not sure why the following solution does not work: type UniqueObject<T extends {[K in keyof U]?: any}, U> = {[K in keyof U]: T[K] extends U[K] ? never : U[K]} var one = { a: 1 } var two1 = { a: 2,