-
Notifications
You must be signed in to change notification settings - Fork 59
feat(mergeOptions): create mergeOptions function and its type
#442
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
base: main
Are you sure you want to change the base?
Conversation
0e67716 to
cd22c2f
Compare
cd22c2f to
5841401
Compare
accf1ea to
4e563c4
Compare
Benchmark Results
Performance regressions of 30% or more should be investigated, unless they were anticipated. Smaller regressions may be due to normal variability, as we don't use dedicated CI infrastructure. |
| class Character { | ||
| constructor( | ||
| public name: string, | ||
| public age: number, | ||
| ) {} | ||
| } | ||
|
|
||
| const anderson = new Character('Thomas A. Anderson', 30) | ||
| const neo = { name: 'Neo', alias: 'The One' } | ||
|
|
||
| _.mergeOptions(anderson, neo) | ||
| // => { name: 'Neo', age: 30, alias: 'The One' } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, interesting. Is there a real world use case for this?
If not, we shouldn't document it.
| ? Expand<NonNullable<A>> | ||
| : Expand<MergeObjects<UndefinedToPartial<NonNullable<A>>, NonNullable<B>>> | ||
|
|
||
| type Expand<T> = T extends object ? { [K in keyof T]: Expand<T[K]> } : T |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This shouldn't be recursive, since mergeOptions isn't.
| ? Expand<NonNullable<B>> | ||
| : [B] extends [undefined] | ||
| ? Expand<NonNullable<A>> | ||
| : Expand<MergeObjects<UndefinedToPartial<NonNullable<A>>, NonNullable<B>>> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't be using NonNullable on A, since that breaks UndefinedToPartial.
src/object/mergeOptions.ts
Outdated
| type MergeObjects<A extends object, B extends object> = { | ||
| [K in keyof A | keyof B]: K extends keyof B | ||
| ? B[K] | ||
| : K extends keyof A | ||
| ? A[K] | ||
| : never | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately, this is too simple. If B[K] is an optional property, then A[K]'s type is still possible.
aleclarson
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR, @fResult! 👍
Summary
Related issue, if any:
#414
For any code change,
Does this PR introduce a breaking change?
No
Bundle impact
src/array/objectify.tssrc/array/sort.tssrc/object/mergeOptions.tsFootnotes
Function size includes the
importdependencies of the function. ↩