Skip to content

Conversation

@fResult
Copy link
Contributor

@fResult fResult commented Oct 9, 2025

Summary

Related issue, if any:

#414

For any code change,

  • Related documentation has been updated, if needed
  • Related tests have been added or updated, if needed
  • Related benchmarks have been added or updated, if needed
  • Release notes in next-minor.md or next-major.md have been added, if needed

Does this PR introduce a breaking change?

No

Bundle impact

Status File Size 1 Difference
M src/array/objectify.ts 91 -6 (-6%)
M src/array/sort.ts 131 -25 (-16%)
A src/object/mergeOptions.ts 88 +88

Footnotes

  1. Function size includes the import dependencies of the function.

@fResult fResult force-pushed the fResult/mergeOptions branch 2 times, most recently from 0e67716 to cd22c2f Compare October 10, 2025 18:10
@fResult fResult force-pushed the fResult/mergeOptions branch from cd22c2f to 5841401 Compare October 10, 2025 18:12
@fResult fResult marked this pull request as ready for review October 10, 2025 20:06
@fResult fResult requested a review from aleclarson as a code owner October 10, 2025 20:06
@fResult fResult force-pushed the fResult/mergeOptions branch from accf1ea to 4e563c4 Compare October 10, 2025 20:07
@radashi-bot
Copy link

radashi-bot commented Oct 10, 2025

Benchmark Results

Name Current
mergeOptions: shallow objects 1,161,646.62 ops/sec ±3.57%
mergeOptions: nested objects (shallow merge only) 1,247,547.18 ops/sec ±2.5%
mergeOptions: object with undefined props 1,204,569.16 ops/sec ±2.71%
mergeOptions: first undefined, second object 4,764,135.18 ops/sec ±0.1%
mergeOptions: first object, second undefined 5,000,801.1 ops/sec ±0.09%
mergeOptions: both undefined 4,985,356.35 ops/sec ±0.09%
mergeOptions: large flat objects (~1000 props) 804.49 ops/sec ±0.87%

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.

Comment on lines +109 to +120
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' }
Copy link
Member

@aleclarson aleclarson Oct 17, 2025

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
Copy link
Member

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>>>
Copy link
Member

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.

Comment on lines 80 to 86
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
}
Copy link
Member

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.

Copy link
Member

@aleclarson aleclarson left a 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! 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants