diff --git a/src/storage.ts b/src/storage.ts index d846ac7..36cf7b1 100644 --- a/src/storage.ts +++ b/src/storage.ts @@ -4,10 +4,9 @@ export function setItem(k: string, v: string): void { export function getItem(k: string): string | null export function getItem(k: string, defaultValue: any): string export function getItem(k: string, defaultValue?: any): string | null { - try { - return localStorage.getItem(k) ?? null - } - catch (e) { - return defaultValue ?? null + const val = localStorage.getItem(k) + if (defaultValue !== undefined && val === null) { + return defaultValue } + return val }