From f31d02d51c885b0c43b57f2d323c6d1aef044724 Mon Sep 17 00:00:00 2001 From: Justin Edmund Date: Mon, 24 Nov 2025 02:01:47 -0800 Subject: [PATCH] fix: replace any types in route pages (10 errors) Phase 1 Batch 3: Route Pages type safety improvements Fixed 10 any-type errors across 7 route page files: 1. src/routes/+page.ts (1 error) - Added PaginationInfo interface for fetchProjects return type 2. src/routes/admin/+layout.svelte (1 error) - Changed children prop from any to Snippet type 3. src/routes/admin/albums/+page.svelte (1 error) - Changed Album.content from any to EditorData type 4. src/routes/admin/universe/+page.svelte (1 error) - Changed form prop from any to Record | null | undefined 5. src/routes/albums/[slug]/+page.svelte (4 errors) - Added AlbumPhoto and AlbumData interfaces - Fixed photo map parameters to use AlbumPhoto - Fixed extractContentPreview to accept EditorData | null - Fixed generateAlbumJsonLd to accept AlbumData 6. src/routes/albums/+page.svelte (1 error) - Changed coverPhoto.colors from any to ColorPalette[] 7. src/routes/photos/[id]/+page.svelte (1 error) - Changed navigateToPhoto parameter from any to PhotoItem | null Progress: 67 any-type errors remaining (down from 77) --- src/routes/+page.ts | 9 +++++++- src/routes/admin/+layout.svelte | 3 ++- src/routes/admin/albums/+page.svelte | 3 ++- src/routes/admin/universe/+page.svelte | 2 +- src/routes/albums/+page.svelte | 3 ++- src/routes/albums/[slug]/+page.svelte | 31 ++++++++++++++++++++++---- src/routes/photos/[id]/+page.svelte | 4 ++-- 7 files changed, 44 insertions(+), 11 deletions(-) diff --git a/src/routes/+page.ts b/src/routes/+page.ts index e3e535d..8959a22 100644 --- a/src/routes/+page.ts +++ b/src/routes/+page.ts @@ -40,9 +40,16 @@ async function fetchRecentAlbums(fetch: typeof window.fetch): Promise { return musicData.albums } +interface PaginationInfo { + total: number + limit: number + offset: number + hasMore: boolean +} + async function fetchProjects( fetch: typeof window.fetch -): Promise<{ projects: Project[]; pagination: any }> { +): Promise<{ projects: Project[]; pagination: PaginationInfo | null }> { const response = await fetch( '/api/projects?projectType=work&includeListOnly=true&includePasswordProtected=true' ) diff --git a/src/routes/admin/+layout.svelte b/src/routes/admin/+layout.svelte index 6cc91e5..001f744 100644 --- a/src/routes/admin/+layout.svelte +++ b/src/routes/admin/+layout.svelte @@ -2,8 +2,9 @@ import { page } from '$app/stores' import AdminNavBar from '$lib/components/admin/AdminNavBar.svelte' import type { LayoutData } from './$types' + import type { Snippet } from 'svelte' - const { children, data } = $props<{ children: any; data: LayoutData }>() + const { children, data } = $props<{ children: Snippet; data: LayoutData }>() const currentPath = $derived($page.url.pathname) const isLoginRoute = $derived(currentPath === '/admin/login') diff --git a/src/routes/admin/albums/+page.svelte b/src/routes/admin/albums/+page.svelte index 842322f..508b610 100644 --- a/src/routes/admin/albums/+page.svelte +++ b/src/routes/admin/albums/+page.svelte @@ -10,6 +10,7 @@ import ErrorMessage from '$lib/components/admin/ErrorMessage.svelte' import Button from '$lib/components/admin/Button.svelte' import Select from '$lib/components/admin/Select.svelte' + import type { EditorData } from '$lib/types/editor' interface Photo { id: number @@ -32,7 +33,7 @@ createdAt: string updatedAt: string photos: Photo[] - content?: any + content?: EditorData _count: { media: number } diff --git a/src/routes/admin/universe/+page.svelte b/src/routes/admin/universe/+page.svelte index 86fccbd..e4b654e 100644 --- a/src/routes/admin/universe/+page.svelte +++ b/src/routes/admin/universe/+page.svelte @@ -3,7 +3,7 @@ import type { PageData } from '../posts/$types' export let data: PageData - export let form: any + export let form: Record | null | undefined diff --git a/src/routes/albums/+page.svelte b/src/routes/albums/+page.svelte index 96d865d..c9685e2 100644 --- a/src/routes/albums/+page.svelte +++ b/src/routes/albums/+page.svelte @@ -5,6 +5,7 @@ import { generateMetaTags } from '$lib/utils/metadata' import { page } from '$app/stores' import type { PageData } from './$types' + import type { ColorPalette } from '$lib/types/photos' interface Album { id: string @@ -21,7 +22,7 @@ width?: number height?: number dominantColor?: string - colors?: any + colors?: ColorPalette[] aspectRatio?: number caption?: string } diff --git a/src/routes/albums/[slug]/+page.svelte b/src/routes/albums/[slug]/+page.svelte index 17f1182..38943af 100644 --- a/src/routes/albums/[slug]/+page.svelte +++ b/src/routes/albums/[slug]/+page.svelte @@ -6,6 +6,29 @@ import { renderEdraContent, getContentExcerpt } from '$lib/utils/content' import { page } from '$app/stores' import type { PageData } from './$types' + import type { EditorData } from '$lib/types/editor' + + interface AlbumPhoto { + id: number + url: string + caption: string | null + filename: string + width: number | null + height: number | null + } + + interface AlbumData { + id: number + slug: string + title: string + description: string | null + content: EditorData | null + location: string | null + date: string | null + createdAt: string + updatedAt: string + photos?: AlbumPhoto[] + } let { data }: { data: PageData } = $props() @@ -14,7 +37,7 @@ // Transform album data to PhotoItem format for MasonryPhotoGrid const photoItems = $derived( - album?.photos?.map((photo: any) => ({ + album?.photos?.map((photo: AlbumPhoto) => ({ id: `photo-${photo.id}`, src: photo.url, alt: photo.caption || photo.filename, @@ -36,7 +59,7 @@ const pageUrl = $derived($page.url.href) // Helper to get content preview using Edra content excerpt utility - const extractContentPreview = (content: any): string => { + const extractContentPreview = (content: EditorData | null): string => { if (!content) return '' return getContentExcerpt(content, 155) } @@ -65,13 +88,13 @@ ) // Generate enhanced JSON-LD for albums with content - const generateAlbumJsonLd = (album: any, pageUrl: string) => { + const generateAlbumJsonLd = (album: AlbumData, pageUrl: string) => { const baseJsonLd = generateImageGalleryJsonLd({ name: album.title, description: album.description, url: pageUrl, images: - album.photos?.map((photo: any) => ({ + album.photos?.map((photo: AlbumPhoto) => ({ url: photo.url, caption: photo.caption })) || [] diff --git a/src/routes/photos/[id]/+page.svelte b/src/routes/photos/[id]/+page.svelte index df1e93c..5b511e3 100644 --- a/src/routes/photos/[id]/+page.svelte +++ b/src/routes/photos/[id]/+page.svelte @@ -8,7 +8,7 @@ import { spring } from 'svelte/motion' import { getCurrentMousePosition } from '$lib/stores/mouse' import type { PageData } from './$types' - import { isAlbum } from '$lib/types/photos' + import { isAlbum, type PhotoItem } from '$lib/types/photos' import ArrowLeft from '$icons/arrow-left.svg' import ArrowRight from '$icons/arrow-right.svg' @@ -110,7 +110,7 @@ }) // Handle photo navigation - function navigateToPhoto(item: any) { + function navigateToPhoto(item: PhotoItem | null) { if (!item) return // Extract media ID from item.id (could be 'media-123' or 'photo-123') const mediaId = item.id.replace(/^(media|photo)-/, '')