|
|
|
|
|
by KrishnaShripad
1375 days ago
|
|
> And I don't know how to express the correct solution (i.e. where we actually assert that A and B are object types). You can do this: function merge<
A extends Record<string, unknown>,
B extends Record<string, unknown>
>(a: A, b: B): A & B {
return { ...a, ...b }
}
const result = merge({ a: 1 }, { b: 2 })
|
|
EDIT: I think this is correct for when `exactOptionalPropertyTypes` is off.
That's for when `exactOptionPropertyTypes` is enabled. With it disabled, then you'd replace `Exclude<B[K], undefined>` with `B[K]`.As to whether this is a good idea. Ah... it's not :P