How to fix Variable 'x' is used before being assigned in TypeScript | DevErrors