TypeScript

Typing async functions (Promise<T>)

Në shqip: Tipet e funksioneve async

ShpjegimiSQ

Një funksion async kthen gjithmonë Promise<T>. Shkruaje tipin e kthimit qartë (Promise<Nxenes[]>) te funksionet publike, që gabimet të dalin aty ku duhet dhe jo te thirrësi.

EnglishEN

An async function always returns Promise<T>. Write the return type explicitly (Promise<Student[]>) on public functions, so errors show up where they belong, not at the caller.

Si ta mendosh

Si një faturë që thotë qartë çfarë do të marrësh kur të vijë porosia.

Lexoje në anglisht

Like a receipt stating clearly what you'll get when the order arrives.

Shembull koditypescript

async function merrNxenesit(): Promise<Nxenes[]> {
  const r = await fetch("/api/nxenesit");
  return r.json();
}

Terma të lidhur