Skip to content

Commit a6d9283

Browse files
committed
add return types
1 parent 3eaee4f commit a6d9283

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

lib/localStorage.ts

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export const saveToLocalStorage = (key: string, value: string) => {
1+
export const saveToLocalStorage = (key: string, value: string): void => {
22
try {
33
if (typeof window !== "undefined") {
44
localStorage.setItem(key, value);
@@ -8,22 +8,23 @@ export const saveToLocalStorage = (key: string, value: string) => {
88
}
99
};
1010

11-
export const loadFromLocalStorage = (key: string) => {
11+
export const loadFromLocalStorage = (key: string): string => {
1212
try {
1313
if (typeof window !== "undefined") {
1414
const value = localStorage.getItem(key);
15-
if (value === null) {
15+
if (value === null || value === undefined) {
1616
return "";
1717
}
1818
return value;
1919
}
20+
return "";
2021
} catch (error) {
2122
console.error("Error reading from localStorage", error);
2223
return "";
2324
}
2425
};
2526

26-
export const removeItemFromLocalStorage = (key: string) => {
27+
export const removeItemFromLocalStorage = (key: string): void => {
2728
if (typeof window !== "undefined") {
2829
localStorage.removeItem(key);
2930
}

0 commit comments

Comments
 (0)