Literal types
Në shqip: Tipet literal
ShpjegimiSQ
Një tip literal lejon vetëm një vlerë të saktë — p.sh. "sq" ose 404. Bashkë me union, krijon lista të mbyllura vlerash: type Gjuha = "sq" | "en". Shkruan gabim „sk“ dhe editori të ndal.
EnglishEN
A literal type allows only one exact value — e.g. "sq" or 404. Combined with unions, it makes closed lists of values: type Language = "sq" | "en". Type “sk” by mistake and the editor stops you.
Si ta mendosh
Si kutitë e votimit me vetëm dy opsione: s'mund të shkruash emrin tënd në vend.
Lexoje në anglisht
Like a ballot with just two options: you can't write in your own name.
Shembull koditypescript
type Gjuha = "sq" | "en";
let g: Gjuha = "sq";
// g = "sk"; // Gabim: s'është "sq" ose "en"