-
Notifications
You must be signed in to change notification settings - Fork 57
New issue
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
type-challenges-solutions/en/medium-merge #251
Comments
A version that is a few characters shorter - type Merge<F, S> = {
[P in keyof (F & S)]: P extends keyof S
? S[P]
: P extends keyof F
? F[P]
: never;
}; |
@zavarka clever 😺 I think there could be some edge-cases with properties in a sense how they will be treated when intersecting them, but for common cases should work, yes. |
Using a util function admittedly ( also from the 'Append to Object' challenge ) but the Collapse ( or Flatten ) just satisfies the tests - without it the solution is equivalent.
|
Why should we use type Merge<F, S> = {
[P in keyof F | keyof S]: P extends keyof S
? S[P]
: F[P]
}; |
@BruceYuj yes, because your key can be either in first set or another one, and you need to filter out one of them. |
Merge
This project is aimed at helping you better understand how the type system works, writing your own utilities, or just having fun with the challenges.
https://ghaiklor.github.io/type-challenges-solutions/en/medium-merge.html
The text was updated successfully, but these errors were encountered: