DEV Community

Nagarajan R
Nagarajan R

Posted on

Answer: How to remove TS2722: Cannot invoke an object which is possibly 'undefined'. error?

TypeScript is saying your onBoundsChanged might be undefined because you have defined it as an optional (?) property in the interface IMapProps:

onBoundsChanged?: {}

Your check for onBoundsChanged for a truthy value is correct, but the event listener will be invoked at a later time, which means onBoundsChanged might be…

Top comments (0)