Commit 67ccfb08 authored by Alejandro Celaya's avatar Alejandro Celaya Committed by Alejandro Celaya

Add more strict return type on LocalStorageService.getObject

parent 4645088e
......@@ -14,6 +14,16 @@ type RefreshOptions = {
persist: boolean;
};
const isTokenInfo = (token: unknown): token is TokenInfo =>
!!token &&
typeof token === 'object' &&
'accessToken' in token &&
typeof token.accessToken === 'string' &&
'refreshToken' in token &&
typeof token.refreshToken === 'string' &&
'expiresAt' in token &&
typeof token.expiresAt === 'number';
/**
* Authorization service.
*
......@@ -96,12 +106,7 @@ export class AuthService extends TinyEmitter {
private _loadToken() {
const token = this._localStorage.getObject(this._storageKey());
if (
!token ||
typeof token.accessToken !== 'string' ||
typeof token.refreshToken !== 'string' ||
typeof token.expiresAt !== 'number'
) {
if (!isTokenInfo(token)) {
return null;
}
......
......@@ -59,7 +59,7 @@ export class LocalStorageService {
/**
* Look up and deserialize a value from storage.
*/
getObject<T = any>(key: string): T | null {
getObject<T = unknown>(key: string): T | null {
const item = this._storage.getItem(key);
return item ? (JSON.parse(item) as T) : null;
}
......
......@@ -67,6 +67,7 @@ export class TagsService {
*/
store(tags) {
// Update the stored (tag, frequency) map.
/** @type Record<string, { text: string; count: number; updated: number }> */
const savedTags = this._storage.getObject(TAGS_MAP_KEY) || {};
tags.forEach(tag => {
if (savedTags[tag]) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment