How to fix Value of type 'string | undefined' is not iterable in TypeScript | DevErrors