TypeScript

unknown

Në shqip përdoret i njëjti emër.

ShpjegimiSQ

unknown është versioni i sigurt i any: mund të mbajë çdo vlerë, por s'të lejon ta përdorësh derisa ta kontrollosh se çfarë është. Ideal për të dhëna që vijnë nga jashtë, si JSON nga një API.

EnglishEN

unknown is the safe version of any: it can hold any value, but won't let you use it until you check what it is. Ideal for data from outside, like JSON from an API.

Si ta mendosh

Si një pako pa etiketë: e pranon, por s'e hap pa e kontrolluar më parë.

Lexoje në anglisht

Like an unlabelled parcel: you accept it, but you don't open it without checking it first.

Shembull koditypescript

const v: unknown = JSON.parse(teksti);
if (typeof v === "string") console.log(v.toUpperCase());   // tani lejohet

Terma të lidhur