Search code examples
angulartypescriptcomponents

Why does this error occur without any changes today : Type 'Player' must have a '[Symbol.iterator]()' method that returns an iterator


enter image description here

Just reloaded an exercise project which was working and now it shows me this error

Symbol.iterator

enter image description here

Here is a part of the component.ts in photograph, I'm lost, can someone help me ?

Added dom.iterable in the tsconfig lib but no changes


Solution

  • As you can find in the mdn documentation, Array.find only returns the first element found in the array, which means your filteredPlayers signal only return a single instance of Player, hence why it is not iterable.

    What you probably want to use is Array.filter which will return all matching element in a new array, which is probably what you wanted to do in the first place :

    filteredPlayers = computer(() => {
      return this.players.filter(player => player.name.includes(this.search()));
    })
    

    Hope this helps.