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