Type inference (TypeScript)
Në shqip: Nxjerrja e tipeve
ShpjegimiSQ
S'ke pse e shkruan tipin kudo: TypeScript-i e kupton vetë nga vlera. const n = 5 është number, dhe [1, 2].map(x => x * 2) është number[]. Shënimet i shkruan kryesisht te parametrat e funksioneve.
EnglishEN
You don't have to write the type everywhere: TypeScript works it out from the value. const n = 5 is a number, and [1, 2].map(x => x * 2) is number[]. You mostly write annotations on function parameters.
Si ta mendosh
Si kamerieri që e kupton nga gota se po pi kafe, pa ta pyetur.
Lexoje në anglisht
Like a waiter who can tell from the cup that you're drinking coffee, without asking.
Shembull koditypescript
const emri = "Arta"; // string
const notat = [5, 4, 3]; // number[]
const mesatarja = notat.reduce((a, b) => a + b) / notat.length; // number