'Why is array.includes() always returning false in React Typescript with useReducer Hook?

Asked the question earlier today, thinking it was a problem that needed async to work, was advised that includes() doesn't need an async implementation and was recommended that I ask again. So, here we go,

I am using .includes() method to check if a word is valid, by checking for inclusion on a 12,000 element or so array. The method always returns false. I've tried to isolate the bug with no success. Perhaps someone can spot an obvious typo or bug I've just over looked? I will include the interfaces at the bottom in case those are helpful.

//helpers.ts
// I have checked to make sure the word is valid, including casing, it doesn't work, even if I pass it a string literal.
export function validateGuess(guess: GuessCharacter[]) {
  let word: string = '';

  for (let character of guess) {
    word += character.value;
  }
 
  return allWords.includes(word);
}

it is called in my reducer

//gameStateReducer.ts
...
case ActionKind.Enter: {
      if (guesses[guessCount][4].value === ' ') {
        console.log('Not enough letters');
        return gameState;
      }

      if (!validateGuess(guesses[guessCount])) {
        console.log('Not in word list');
        return gameState;
      }

      //continues process and returns updated state
      ...
    }

which is called by the event handler

//index.ts, modified, I actually pass a whole object but it's a little verbose for the post/issue
  function handleEnterPress() {
    dispatch(keyAction.Enter);
  }

which is the callback in this component

//Keyboard.tsx
<button className="enter-button" onClick={handleEnterPress}>
  ENTER
</button>
interface GuessCharacter {
  value: string;
  place: number; //zero-indexed
  correctValue: boolean;
  correctPlace: boolean;
  submitted: boolean;
}

interface GameState {
  solution: string;
  guesses: GuessCharacter[][];
  guessCount: number; //zero-indexed
  characterBank: KeyboardCharacter[];
}

Thanks, my apologies if there is an assumption that I left unstated, I have reread the post and hope my question is good to go.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source