Skip to content

Commit 38fb646

Browse files
committed
Fix folder icon type guards
1 parent 523613b commit 38fb646

2 files changed

Lines changed: 11 additions & 6 deletions

File tree

apps/desktop/src/main/vault.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,10 @@ const VALID_FOLDER_ICON_IDS = new Set<FolderIconId>([
9797
'home'
9898
])
9999

100+
function isFolderIconId(value: unknown): value is FolderIconId {
101+
return typeof value === 'string' && VALID_FOLDER_ICON_IDS.has(value as FolderIconId)
102+
}
103+
100104
const DEFAULT_VAULT_SETTINGS: VaultSettings = {
101105
primaryNotesLocation: 'inbox',
102106
dailyNotes: {
@@ -356,8 +360,7 @@ function normalizeVaultSettings(
356360
const folderIcons: Record<string, FolderIconId> = {}
357361
if (candidate.folderIcons && typeof candidate.folderIcons === 'object') {
358362
for (const [key, iconId] of Object.entries(candidate.folderIcons)) {
359-
if (!key || typeof iconId !== 'string') continue
360-
if (!VALID_FOLDER_ICON_IDS.has(iconId as FolderIconId)) continue
363+
if (!key || !isFolderIconId(iconId)) continue
361364
folderIcons[key] = iconId
362365
}
363366
}

packages/app-core/src/lib/vault-layout.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@ const VALID_FOLDER_ICON_IDS = new Set<FolderIconId>([
5050
'home'
5151
])
5252

53+
function isFolderIconId(value: unknown): value is FolderIconId {
54+
return typeof value === 'string' && VALID_FOLDER_ICON_IDS.has(value as FolderIconId)
55+
}
56+
5357
function pad(n: number): string {
5458
return n.toString().padStart(2, '0')
5559
}
@@ -66,10 +70,8 @@ export function normalizeVaultSettings(
6670
const normalizedFolderIcons: Record<string, FolderIconId> = {}
6771
if (folderIcons && typeof folderIcons === 'object') {
6872
for (const [key, value] of Object.entries(folderIcons)) {
69-
if (!key || typeof value !== 'string') continue
70-
if (VALID_FOLDER_ICON_IDS.has(value as FolderIconId)) {
71-
normalizedFolderIcons[key] = value
72-
}
73+
if (!key || !isFolderIconId(value)) continue
74+
normalizedFolderIcons[key] = value
7375
}
7476
}
7577
return {

0 commit comments

Comments
 (0)