How to fix Cannot read properties of null (reading 'x') in TypeScript | DevErrors