Skip to content

Commit

Permalink
chore: add typings to localstorage interface
Browse files Browse the repository at this point in the history
  • Loading branch information
CSharperMantle committed May 24, 2023
1 parent 6b734e5 commit cc2046b
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/customization/history/History.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export class History implements ILocalStorageSerializable {
}

public static fromLocalStorage(): History {
const result = retrieve(HistoryLocalStorageKey)
const result = retrieve<History>(HistoryLocalStorageKey)

if (isNil(result)) return History.Empty

Expand Down
2 changes: 1 addition & 1 deletion src/customization/settings/Settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ export class Settings implements ILocalStorageSerializable {
}

public static fromLocalStorage(): Settings {
const result = retrieve(SettingsLocalStorageKey)
const result = retrieve<Settings>(SettingsLocalStorageKey)

if (isNil(result)) return Settings.Default

Expand Down
5 changes: 2 additions & 3 deletions src/localstorage/LocalStorageManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,17 @@ export function store<T = unknown>(key: string, value: T): boolean {
try {
window.localStorage.setItem(key, JSON.stringify(value))
} catch (err: unknown) {
console.warn(err)
return false
}
return true
}

export function retrieve(key: string): unknown {
export function retrieve<T = unknown>(key: string): T | null {
if (!isBrowser) return null

const result = window.localStorage.getItem(key)
if (!isNil(result)) {
return JSON.parse(result)
return JSON.parse(result) as T
} else {
return null
}
Expand Down

0 comments on commit cc2046b

Please sign in to comment.