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

merge date bug #100

Closed
171h opened this issue Jun 29, 2023 · 1 comment · Fixed by #111
Closed

merge date bug #100

171h opened this issue Jun 29, 2023 · 1 comment · Fixed by #111

Comments

@171h
Copy link

171h commented Jun 29, 2023

Environment

defu development environment

Reproduction

.

Describe the bug

// this repo/test/defu.test.ts

  it('merge Date', () => {
    const defaultObj = { date: new Date(), date2: new Date() }
    const obj2 = { date: new Date('2021-01-01'), date2: new Date('2021-01-02') }
    const obj3 = { date: '2021-01-01', date2: '2021-01-02' }
    console.log(obj2)
    const newObj2 = defu(obj2,  defaultObj)
    const newObj3 = defu(obj3,  defaultObj)
    console.log('results', { defaultObj, obj2, obj3, newObj2, newObj3 })
  })

// output

RERUN  test/defu.test.ts x35

stdout | test/defu.test.ts > defu > merge Date
results {
  defaultObj: { date: 2023-06-29T03:44:08.346Z, date2: 2023-06-29T03:44:08.346Z },
  obj2: { date: 2021-01-01T00:00:00.000Z, date2: 2021-01-02T00:00:00.000Z },
  obj3: { date: '2021-01-01', date2: '2021-01-02' },
  newObj2: { date: {}, date2: {} },
  newObj3: { date: '2021-01-01', date2: '2021-01-02' }
}

results.newObj2 should toBe obj2

Additional context

.

Logs

.
@darvids0n
Copy link

darvids0n commented Jul 21, 2023

Probably the correct way to use objects that you don't want defu to try and deep-merge, is to convert them toString() before setting into your input or defaults objects. Defu is a minimal implementation and this would be the only special case, which seems wrong.

@pi0 pi0 mentioned this issue Oct 24, 2023
8 tasks
@pi0 pi0 closed this as completed in #111 Oct 24, 2023
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 a pull request may close this issue.

2 participants