Recently, I created a small function that is able to perform multi-dimensional combinations of array elements. Here is an example:
test('combine', () => {
const result = combine([[[1, 2], [3, 4]], [['a', 'b'], ['c', 'd']]])
expect(result).toStrictEqual([
[[ 1, 2], ["a", "b"]],
[[ 1, 2], ["c", "d"]],
[[ 3, 4], ["a", "b"]],
[[ 3, 4], ["c", "d"]],
]
)
})
While the function successfully functions as intended, I encountered a TypeScript error when omitting // @ts-ignore
. The error message displayed was as follows:
export const combine = (arr: Array<unknown>) => R.apply(R.liftN(arr.length, (...args) => args), arr)
TS2769: No overload matches this call.
The last overload gave the following error.
Argument of type 'unknown[]' is not assignable to parameter of type '[]'.
Target allows only 0 element(s) but source may have more.
7 |
> 8 | export const combine = (arr: Array<unknown>) => R.apply(R.liftN(arr.length, (...args) => args), arr)
| ^^^
I would greatly appreciate any guidance or assistance with resolving this issue. Thank you.