I managed to write this code which seems to work well (what it does is not the point here):
export function countUniqueValues<Type extends string|number = string>(values: Type[]): number {
return new Set<Type>(values).size;
}
But my first attempt led to a "no overload matches this call" error:
export function countUniqueValues(values: string[]|number[]): number {
return new Set(values).size; // Error TS2769
}
Can you explain why the second solution is not valid for TypeScript?