fastify / deepmerge

Merges the enumerable properties of two or more objects deeply. Fastest implementation of deepmerge
Other
80 stars 11 forks source link

Incorrect types for readonly arrays #22

Closed russelldavis closed 1 year ago

russelldavis commented 1 year ago

Prerequisites

Fastify version

N/A

Plugin version

No response

Node.js version

N/A

Operating system

macOS

Operating system version (i.e. 20.04, 11.3, 10)

N/A

Description

The return value of deepmerge is incorrect when the inputs contain a readonly array.

Steps to Reproduce

import makeDeepmerge from "@fastify/deepmerge";
const deepmerge = makeDeepmerge();
const a1 = ['a', 'b'] as const;
const a2 = ['c'] as const;
const m = deepmerge(a1, a2);

The type of m is readonly ["c"] which is incorrect.

Expected Behavior

The type of m should be ["a" | "b" | "c"] (or even better, ["a", "b", "c"] in this case since the inputs are tuples).

mcollina commented 1 year ago

Thanks for reporting! Would you like to send a Pull Request to address this issue? Remember to add unit tests.