From 36759bf0562bb2b9015fa807ce1c421b7106db85 Mon Sep 17 00:00:00 2001 From: Tom Nick Date: Wed, 5 Jun 2024 23:39:58 +0200 Subject: [PATCH] fix: some type errors --- .../Game/GameControls/GameControlNumbers.tsx | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/components/pages/Game/GameControls/GameControlNumbers.tsx b/src/components/pages/Game/GameControls/GameControlNumbers.tsx index 016f306..f8064d4 100644 --- a/src/components/pages/Game/GameControls/GameControlNumbers.tsx +++ b/src/components/pages/Game/GameControls/GameControlNumbers.tsx @@ -52,10 +52,15 @@ class SudokuMenuNumbers extends React.Component { const occurrences = this.props.sudoku.filter((c) => c.number === n).length; const conflicting = SudokuGame.conflictingFields(this.props.sudoku); - const activeCell = this.props.sudoku[this.props.activeCell!.y * 9 + this.props.activeCell!.x]; - const userNotes = activeCell.notes; - const conflictingCell = conflicting[this.props.activeCell!.y * 9 + this.props.activeCell!.x]; - const autoNotes = this.props.showHints ? conflictingCell.possibilities : []; + + const activeCell = this.props.activeCell + ? this.props.sudoku[this.props.activeCell.y * 9 + this.props.activeCell.x] + : undefined; + const userNotes = activeCell?.notes ?? []; + const conflictingCell = this.props.activeCell + ? conflicting[this.props.activeCell.y * 9 + this.props.activeCell.x] + : undefined; + const autoNotes = (this.props.showHints ? conflictingCell?.possibilities : []) ?? []; const setNumberOrNote = () => { if (this.props.notesMode) { @@ -81,7 +86,7 @@ class SudokuMenuNumbers extends React.Component { userNotes.length === 0 && autoNotes.includes(n) && !userNotes.includes(n) && - activeCell.number === 0, + activeCell?.number === 0, })} onClick={setNumberOrNote} key={n}