From e62395435166b132c75c4c13309b9498f19f1ece Mon Sep 17 00:00:00 2001 From: kolaente Date: Fri, 30 Sep 2022 13:27:14 +0200 Subject: [PATCH] chore: better typing --- src/helpers/defaultReminder.ts | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/src/helpers/defaultReminder.ts b/src/helpers/defaultReminder.ts index 3df722fb..03504611 100644 --- a/src/helpers/defaultReminder.ts +++ b/src/helpers/defaultReminder.ts @@ -1,10 +1,7 @@ const DEFAULT_REMINDER_KEY = 'defaultReminder' export const AMOUNTS_IN_SECONDS: { - minutes: number, - hours: number, - days: number, - months: number, + [type in SavedReminderSettings['type']]: number } = { minutes: 60, hours: 60 * 60, @@ -19,15 +16,15 @@ interface DefaultReminderSettings { interface SavedReminderSettings { enabled: boolean, - amount?: number, - type?: 'minutes' | 'hours' | 'days' | 'months', + amount: number, + type: 'minutes' | 'hours' | 'days' | 'months', } -function calculateDefaultReminderSeconds(type: string, amount: number): number { +function calculateDefaultReminderSeconds(type: SavedReminderSettings['type'], amount: number): number { return amount * (AMOUNTS_IN_SECONDS[type] || 0) } -export function saveDefaultReminder(enabled: boolean, type: string, amount: number) { +export function saveDefaultReminder(enabled: boolean, type: SavedReminderSettings['type'], amount: number) { const defaultReminderSeconds = calculateDefaultReminderSeconds(type, amount) localStorage.setItem(DEFAULT_REMINDER_KEY, JSON.stringify({ enabled, @@ -83,6 +80,8 @@ export function getSavedReminderSettings(): SavedReminderSettings | null { if (!s.enabled) { return { enabled: false, + type: 'minutes', + amount: 0, } }