From 2059a5d427d43a29fb4e6e33fb4b92e466d14f67 Mon Sep 17 00:00:00 2001 From: Serraniel Date: Mon, 28 Dec 2020 22:27:38 +0100 Subject: [PATCH] #48 Added types to helper --- src/javascript/utils/helpers.ts | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/javascript/utils/helpers.ts b/src/javascript/utils/helpers.ts index 053aa18..12dd315 100644 --- a/src/javascript/utils/helpers.ts +++ b/src/javascript/utils/helpers.ts @@ -1,16 +1,16 @@ -export var isShiftPressed = false; -export var isCtrlPressed = false; +export var isShiftPressed: boolean = false; +export var isCtrlPressed: boolean = false; -export function isHtmlElement(object) { +export function isHtmlElement(object: any) { return object instanceof HTMLElement; } -export function initHelpers() { +export function initHelpers(): void { document.addEventListener('keydown', event => handleKeyDown(event)); document.addEventListener('keyup', event => handleKeyUp(event)); } -export function onReady(fn) { +export function onReady(fn: () => void) { if (document.readyState != 'loading') { fn(); } else { @@ -18,19 +18,19 @@ export function onReady(fn) { } } -export function assigned(obj) { +export function assigned(obj: any): boolean { return !(typeof obj === 'undefined' || obj === null); } -function handleKeyDown(event) { +function handleKeyDown(event: KeyboardEvent) { handleKeyToggle(event, true); } -function handleKeyUp(event) { +function handleKeyUp(event: KeyboardEvent) { handleKeyToggle(event, false); } -function handleKeyToggle(event, isPressed) { +function handleKeyToggle(event: KeyboardEvent, isPressed: boolean) { if (event.key === 'Shift') { isShiftPressed = isPressed; } else if (event.key === 'Control') {