Skip to content
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

[REQUEST] assign - How to keep object references #416

Open
xmsz-stu opened this issue Jun 26, 2024 · 0 comments
Open

[REQUEST] assign - How to keep object references #416

xmsz-stu opened this issue Jun 26, 2024 · 0 comments

Comments

@xmsz-stu
Copy link

Currently, the assign function creates new object references during the merge process.
I want to keep the object references. like this

export const assign = <X extends Record<string | symbol | number, any>>(
  initial: X,
  override: X
): X => {
  if (!initial || !override) return initial ?? override ?? {}

  for (const [key, value] of Object.entries(override)) {
    if (isObject(initial[key]) && isObject(value)) {
      assign(initial[key], value)
    } else {
      initial[key] = value
    }
  }

  return initial
}
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

No branches or pull requests

1 participant