The concat
solution doesn’t typecheck because of the empty array literal. You’d need to write
const arr = ([] as number[]).concat(input);
Alternatively, you can use flat
:
const arr = [input].flat();
This would not only be shorter but also preferable because it doesn’t rely on the concat-spreadable property of the input but actually checks for arrays.
CLICK HERE to find out more related problems solutions.