[typescript]advanced function overload

Wed Apr 16

typescript

Author:Noritaka

Astro
function toUppeCase(x: string): string
function toUppeCase(x: number): number
function toUppeCase(x: string | number): string | number {
  if (typeof x === 'string') {
    return x.toUpperCase()
  }
  return x;
}
const upperHello = toUppeCase('hello');

typescript