How to fix Cannot invoke an object which is possibly 'undefined'. in TypeScript | DevErrors