TypeScript

catch (e: unknown)

Në shqip: Gabimet si unknown

ShpjegimiSQ

Në strict mode, gabimi te catch është unknown, sepse JS mund të hedhë çdo gjë (edhe tekst). Duhet ta kontrollosh: if (e instanceof Error) console.log(e.message).

EnglishEN

In strict mode, the error in catch is unknown, because JS can throw anything (even a string). You have to check it: if (e instanceof Error) console.log(e.message).

Si ta mendosh

Si një pako pa etiketë: e kontrollon para se ta hapësh.

Lexoje në anglisht

Like an unlabelled parcel: you check it before opening.

Shembull koditypescript

try { await ngarko(); }
catch (e) {
  console.error(e instanceof Error ? e.message : String(e));
}

Terma të lidhur