Skip to content

mergePartial doesn't correctly work with union types #479

@markov00

Description

@markov00

Describe the bug
If you have an interface with a field that contains an union type like the one in the example,
mergePartial with mergeOptionalParams option to true result in a wrongly merged object.

To Reproduce
Steps to reproduce the behavior:

test('should override union types', () => {
  type TestObject = { string1?: string; string2?: string };
  interface TestUnionType {
    union: 'val1' | 'val2' | TestObject;
  }
  expect(
    mergePartial<TestUnionType>(
      { union: { string1: 'other' } },
      { union: 'val2' },
      { mergeOptionalPartialValues: true },
    ),
  ).toEqual({ union: 'val2' });
});

the received object is

Object {
        "union": Object {
    +     "0": "v",
    +     "1": "a",
    +     "2": "l",
    +     "3": "2",
          "string1": "other",
        },
      }

Expected behavior
I'm expecting that the partial object completely replace the original one

Screenshots
n/a

Version (please complete the following information):

  • Elastic Charts: 15.x

Additional context

I was adding a new Mock utility to mock settings specs. In the settings spec, the tooltipType is typed as tooltip: TooltipType | TooltipProps;. I was following the example of the MockSeriesSpecs, but if I try to merge a default like

tooltip: {
      type: TooltipType.VerticalCursor,
      snap: true,
    },

with

tooltip: TooltipType.None

I'm getting this bad merge.

Metadata

Metadata

Assignees

Labels

:specsChart specifications related issuebugSomething isn't workingreleasedIssue released publicly

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions