“Object is possibly 'undefined'”
Në shqip: Gabimi „possibly undefined“
ShpjegimiSQ
TypeScript të paralajmëron që vlera mund të mungojë — p.sh. rezultati i find() ose një fushë opsionale. Zgjidhjet: kontrollo me if, përdor ?. dhe ??, ose (vetëm kur je i sigurt) !.
EnglishEN
TypeScript warns you the value might be missing — e.g. the result of find() or an optional field. Fixes: check with an if, use ?. and ??, or (only when you're sure) !.
Si ta mendosh
Si një paralajmërim „kutia mund të jetë bosh“.
Lexoje në anglisht
Like a “box may be empty” warning.
Shembull koditypescript
const n = nxenesit.find((x) => x.id === 1);
console.log(n.emri); // ✗ possibly undefined
console.log(n?.emri); // ✓