We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
We notice the following issue described in this playground.
The type inferred when merging two objects trough a generic function is always resolved to T & U which is inexact if T shares keys with U.
T & U
T
U
The correct inferred type of const mergeObjects = <A, B>(a: A, b: B) => ({ ...a, ...b });
const mergeObjects = <A, B>(a: A, b: B) => ({ ...a, ...b });
should be
type Merge<T, U> = { [k in Exclude<keyof T, keyof U>]: T[k]; } & { [l in Exclude<keyof U, keyof T>]: U[l]; } & { [l in keyof (T | U)]: T[l] | U[l] }; <A, B>(a: A, b: B) => Merge<A, B>
As shown in the playground, the correct type is inferred when using the spread operator with concrete types.
The text was updated successfully, but these errors were encountered:
The proposed definition is much more complex yet still not fully accurate because it can't account for aliasing effects.
See discussion in #28234
Sorry, something went wrong.
This issue has been marked as a 'Duplicate' and has seen no recent activity. It has been automatically closed for house-keeping purposes.
Thanks for pointing it out.
No branches or pull requests
We notice the following issue described in this playground.
TL;DR;
The type inferred when merging two objects trough a generic function is always resolved to
T & U
which is inexact ifT
shares keys withU
.The correct inferred type of
const mergeObjects = <A, B>(a: A, b: B) => ({ ...a, ...b });
should be
As shown in the playground, the correct type is inferred when using the spread operator with concrete types.
The text was updated successfully, but these errors were encountered: