typescript-go icon indicating copy to clipboard operation
typescript-go copied to clipboard

Error on unused generic type argument when declaring multiple function signatures

Open jkieboom opened this issue 7 months ago • 0 comments

Declaring multiple function signatures that receive a generic type parameter T allows for some of the signatures not to use T but still declare it in current typescript. In the native port however this generates an error.

export function max<T>(a: undefined, b: undefined): undefined;
export function max<T extends number>(
  a: T | undefined,
  b: T | undefined
): T | undefined;

export function max<T extends number>(
  a: T | undefined,
  b: T | undefined
): T | undefined {
  return a ?? b;
}

Arguably this should have been an error before, but it's currently allowed.

jkieboom avatar May 26 '25 20:05 jkieboom