TS2558

error TS2558: Expected 2 type arguments, but got 1.

Broken Code ❌

1
2
3
4
5
function combine<X, Y>(a: X, b: Y): (X | Y)[] {
return [a, b];
}

combine<number>(1, '2');

Fixed Code ✔️

The combine function defines 2 type variables (X & Y), so you have to pass it 2 type arguments:

1
2
3
4
5
function combine<X, Y>(a: X, b: Y): (X | Y)[] {
return [a, b];
}

combine<number, string>(1, '2');