TS2769

error TS2769: No overload matches this call.

Bad Code ❌

1
const sessions = [].concat(...bestConfigs);

Fixed Code ✔️

When proving just an empty array ([]), then TypeScript does not know what type of elements can be stored in this array. That’s why there is no overload which matches when adding values from a typed array (such as bestConfigs) to an untyped array. The solution here is to provide a typed array of the same type as the array that is being used for concatenation.

1
2
3
4
5
const sessions = ([] as Config[]).concat(...bestConfigs);

// Alternative:
const typedArray: Config[] = [];
const sessions = typedArray.concat(...bestConfigs);