Typeseedcordv0.10.6
Merge
Merge two types into a new type. Keys of the second type overrides keys of the first type.
This is different from the TypeScript && (intersection) operator. With &&, conflicting property types are intersected, which often results in nevernever. For example, {a: string} & {a: number}{a: string} & {a: number} makes aa become string & numberstring & number, which resolves to nevernever. With MergeMerge, the second type's keys cleanly override the first, so Merge<{a: string}, {a: number}>Merge<{a: string}, {a: number}> gives {a: number}{a: number} as expected. MergeMerge also produces a flattened type (via SimplifySimplify), making it more readable in IDE tooltips compared to A & BA & B.
See also:ObjectMerge Object
type Merge<Destination, Source> = Destination extends unknown // For distributing `Destination` ? Source extends unknown // For distributing `Source` ? If<IsEqual<Destination, Source>, Destination, _Merge<Destination, Source>> : never // Should never happen : nevertype Merge<Destination, Source> = Destination extends unknown // For distributing `Destination` ? Source extends unknown // For distributing `Source` ? If<IsEqual<Destination, Source>, Destination, _Merge<Destination, Source>> : never // Should never happen : neverDestination
DestinationDestinationSource
SourceSource