Function overloads (TypeScript)
Në shqip: Mbingarkimi i funksioneve në TypeScript
ShpjegimiSQ
Me overload-e mund të përshkruash disa mënyra si thirret i njëjti funksion — p.sh. me tekst kthen tekst, me numër kthen numër — dhe TypeScript-i zgjedh tipin e duhur sipas argumentit.
EnglishEN
With overloads you can describe several ways to call the same function — e.g. with text it returns text, with a number it returns a number — and TypeScript picks the right type based on the argument.
Si ta mendosh
Si një sportel që pranon edhe letra, edhe pako, dhe të jep faturën e duhur për secilën.
Lexoje në anglisht
Like a counter that accepts both letters and parcels and gives you the right receipt for each.
Shembull koditypescript
function dyfisho(x: string): string;
function dyfisho(x: number): number;
function dyfisho(x: any) { return typeof x === "string" ? x + x : x * 2; }