From 714c01b9656553033dafc61c531d877b6d3d838e Mon Sep 17 00:00:00 2001 From: sean <135666428+seantiz@users.noreply.github.com> Date: Mon, 20 May 2024 23:25:25 +0100 Subject: [PATCH] Define explicit types for handler functions in App.tsx --- src/app/App.tsx | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/app/App.tsx b/src/app/App.tsx index fb18fba..2dd88dc 100644 --- a/src/app/App.tsx +++ b/src/app/App.tsx @@ -19,6 +19,11 @@ type LocalAsset = { classification: Pieces.ClassificationSpecificEnum, } +type SnippetSelector = ( arg: number ) => void; +type SnippetDeselector = () => void; +type KeyboardInputHandler = ( arg: React.KeyboardEvent ) => void; +type FormHandler = (event: React.BaseSyntheticEvent) => void; + //=============================[GLOBALS]================================// let full_context: JSON; export var applicationData: Application; @@ -50,16 +55,16 @@ export function App(): React.JSX.Element { setArray([]) } - const handleSelect = (index) => { + const handleSelect: SnippetSelector = (index) => { setSelectedIndex(index!=selectedIndex?index:-1); }; - const handleDeSelect = () => { + const handleDeSelect: SnippetDeselector = () => { setSelectedIndex(-1) }; // Keyboard event handler - const handleKeyPress = (event) => { + const handleKeyPress: KeyboardInputHandler = (event) => { // Check if 'Cmd' on MacOS or 'Ctrl' on Windows is pressed along with '\' if ((event.metaKey || event.ctrlKey) && event.key === '\\') { handleDeSelect(); @@ -116,7 +121,7 @@ export function App(): React.JSX.Element { const [searchTerm, setSearchTerm] = useState('') const [searchResult, setSearchResult] = useState('') - const handleSearch = async (event) => { + const handleSearch: FormHandler = async (event) => { event.preventDefault() const searchTerm = event.target.elements['search-term'].value if (!searchTerm) {