TypeScript

Explicit return types

Në shqip: Tipet e shprehura të kthimit

ShpjegimiSQ

TS e nxjerr tipin e kthimit vetë, por te funksionet e eksportuara është mirë ta shkruash: dokumenton qëllimin, gabimet dalin brenda funksionit dhe kontrolli i tipeve shpejtohet.

EnglishEN

TS infers the return type itself, but on exported functions it's good to write it: it documents intent, errors surface inside the function and type-checking speeds up.

Si ta mendosh

Si të shkruash në kopertinë çfarë ka brenda kutisë.

Lexoje në anglisht

Like writing on the lid what's inside the box.

Shembull koditypescript

export function mesatarja(notat: number[]): number {
  return notat.reduce((a, b) => a + b, 0) / notat.length;
}

Terma të lidhur