Skip to content

merge date bug #100

Closed
Closed

Description

@171h

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

.

Activity

  1. darvids0n commented on Jul 21, 2023

    @darvids0n

    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.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions