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