fix: replace any types in admin and utility files (11 errors)

Phase 1 Batch 8: Admin & Misc type safety improvements - PHASE 1 COMPLETE

Fixed 11 any-type errors across 7 files:

1. src/lib/admin/autoSave.svelte.ts (1 error)
   - Fixed catch block: e: unknown (line 98)

2. src/lib/admin/autoSave.ts (1 error)
   - Fixed catch block: e: unknown (line 85)

3. src/lib/admin/autoSaveLifecycle.ts (2 errors)
   - Fixed controller type: AutoSaveStore<unknown, unknown> (line 13)

4. src/lib/admin/api.ts (1 error)
   - Fixed body cast: body as FormData (line 61)

5. src/lib/server/api-utils.ts (3 errors)
   - Fixed jsonResponse data: unknown (line 5)
   - Fixed isValidStatus parameter: unknown (line 46)
   - Fixed isValidPostType parameter: unknown (line 54)

6. src/lib/stores/project-form.svelte.ts (1 error)
   - Fixed setField value: unknown (line 57)

7. src/lib/stores/toast.ts (2 errors)
   - Fixed error callback: error: unknown (line 70)
   - Fixed custom component: unknown (line 85)

Progress: 0 any-type errors remaining!
PHASE 1 TYPE SAFETY: COMPLETE (103 errors fixed)
This commit is contained in:
Justin Edmund 2025-11-24 02:43:52 -08:00
parent cac556a816
commit 4782584a47
7 changed files with 10 additions and 10 deletions

View file

@ -58,7 +58,7 @@ export async function request<TResponse = unknown, TBody = unknown>(
const res = await fetch(url, {
method,
headers: mergedHeaders,
body: body ? (isFormData ? (body as any) : JSON.stringify(body)) : undefined,
body: body ? (isFormData ? (body as FormData) : JSON.stringify(body)) : undefined,
signal,
credentials: 'same-origin'
})

View file

@ -95,7 +95,7 @@ export function createAutoSaveStore<TPayload, TResponse = unknown>(
lastSentHash = hash
setStatus('saved')
if (opts.onSaved) opts.onSaved(res, { prime })
} catch (e: any) {
} catch (e: unknown) {
if (e?.name === 'AbortError') {
// Newer save superseded this one
return

View file

@ -82,7 +82,7 @@ export function createAutoSaveController<TPayload, TResponse = unknown>(
lastSentHash = hash
setStatus('saved')
if (opts.onSaved) opts.onSaved(res, { prime })
} catch (e: any) {
} catch (e: unknown) {
if (e?.name === 'AbortError') {
// Newer save superseded this one
return

View file

@ -10,7 +10,7 @@ interface AutoSaveLifecycleOptions {
}
export function initAutoSaveLifecycle(
controller: AutoSaveController | AutoSaveStore<any, any>,
controller: AutoSaveController | AutoSaveStore<unknown, unknown>,
options: AutoSaveLifecycleOptions = {}
) {
const { isReady = () => true, onFlushError, enableShortcut = true } = options

View file

@ -2,7 +2,7 @@ import type { RequestEvent } from '@sveltejs/kit'
import { getSessionUser } from '$lib/server/admin/session'
// Response helpers
export function jsonResponse(data: any, status = 200): Response {
export function jsonResponse(data: unknown, status = 200): Response {
return new Response(JSON.stringify(data), {
status,
headers: { 'Content-Type': 'application/json' }
@ -43,7 +43,7 @@ export function getPaginationMeta(total: number, page: number, limit: number) {
export const VALID_STATUSES = ['draft', 'published'] as const
export type Status = (typeof VALID_STATUSES)[number]
export function isValidStatus(status: any): status is Status {
export function isValidStatus(status: unknown): status is Status {
return VALID_STATUSES.includes(status)
}
@ -51,7 +51,7 @@ export function isValidStatus(status: any): status is Status {
export const VALID_POST_TYPES = ['post', 'essay'] as const
export type PostType = (typeof VALID_POST_TYPES)[number]
export function isValidPostType(type: any): type is PostType {
export function isValidPostType(type: unknown): type is PostType {
return VALID_POST_TYPES.includes(type)
}

View file

@ -54,7 +54,7 @@ export function createProjectFormStore(initialProject?: Project | null) {
isDirty,
// Methods for controlled mutation
setField(key: keyof ProjectFormData, value: any) {
setField(key: keyof ProjectFormData, value: unknown) {
fields[key] = value
},

View file

@ -67,7 +67,7 @@ export const toast = {
messages: {
loading: string
success: string | ((data: T) => string)
error: string | ((error: any) => string)
error: string | ((error: unknown) => string)
},
options?: ToastOptions
) => {
@ -82,7 +82,7 @@ export const toast = {
},
// Custom toast with full control
custom: (component: any, options?: ToastOptions) => {
custom: (component: unknown, options?: ToastOptions) => {
return sonnerToast.custom(component, {
...defaultOptions,
...options