Skip to content

.merge() does not skip undefined values #1111

@adamcikado

Description

@adamcikado

Package version

21.6.1

Describe the bug

If you call .merge() with object that has property with undefined value, it will actually update the attribute. It should instead skip the property.

Example

type UpdateUserProps = {
  email?: string
  password?: string
  currentPassword?: string
}

export class UserService {
  async update(user: User, payload: UpdateUserProps) {
    user.merge({
      email: payload.email,
      password: payload.password,
    }) 

    return await user.save()
  }
}

Calling userService.update(user, { password: 'test' }) would set email to undefined.

Reproduction repo

No response

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