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:
parent
cac556a816
commit
4782584a47
7 changed files with 10 additions and 10 deletions
|
|
@ -58,7 +58,7 @@ export async function request<TResponse = unknown, TBody = unknown>(
|
||||||
const res = await fetch(url, {
|
const res = await fetch(url, {
|
||||||
method,
|
method,
|
||||||
headers: mergedHeaders,
|
headers: mergedHeaders,
|
||||||
body: body ? (isFormData ? (body as any) : JSON.stringify(body)) : undefined,
|
body: body ? (isFormData ? (body as FormData) : JSON.stringify(body)) : undefined,
|
||||||
signal,
|
signal,
|
||||||
credentials: 'same-origin'
|
credentials: 'same-origin'
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -95,7 +95,7 @@ export function createAutoSaveStore<TPayload, TResponse = unknown>(
|
||||||
lastSentHash = hash
|
lastSentHash = hash
|
||||||
setStatus('saved')
|
setStatus('saved')
|
||||||
if (opts.onSaved) opts.onSaved(res, { prime })
|
if (opts.onSaved) opts.onSaved(res, { prime })
|
||||||
} catch (e: any) {
|
} catch (e: unknown) {
|
||||||
if (e?.name === 'AbortError') {
|
if (e?.name === 'AbortError') {
|
||||||
// Newer save superseded this one
|
// Newer save superseded this one
|
||||||
return
|
return
|
||||||
|
|
|
||||||
|
|
@ -82,7 +82,7 @@ export function createAutoSaveController<TPayload, TResponse = unknown>(
|
||||||
lastSentHash = hash
|
lastSentHash = hash
|
||||||
setStatus('saved')
|
setStatus('saved')
|
||||||
if (opts.onSaved) opts.onSaved(res, { prime })
|
if (opts.onSaved) opts.onSaved(res, { prime })
|
||||||
} catch (e: any) {
|
} catch (e: unknown) {
|
||||||
if (e?.name === 'AbortError') {
|
if (e?.name === 'AbortError') {
|
||||||
// Newer save superseded this one
|
// Newer save superseded this one
|
||||||
return
|
return
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@ interface AutoSaveLifecycleOptions {
|
||||||
}
|
}
|
||||||
|
|
||||||
export function initAutoSaveLifecycle(
|
export function initAutoSaveLifecycle(
|
||||||
controller: AutoSaveController | AutoSaveStore<any, any>,
|
controller: AutoSaveController | AutoSaveStore<unknown, unknown>,
|
||||||
options: AutoSaveLifecycleOptions = {}
|
options: AutoSaveLifecycleOptions = {}
|
||||||
) {
|
) {
|
||||||
const { isReady = () => true, onFlushError, enableShortcut = true } = options
|
const { isReady = () => true, onFlushError, enableShortcut = true } = options
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@ import type { RequestEvent } from '@sveltejs/kit'
|
||||||
import { getSessionUser } from '$lib/server/admin/session'
|
import { getSessionUser } from '$lib/server/admin/session'
|
||||||
|
|
||||||
// Response helpers
|
// Response helpers
|
||||||
export function jsonResponse(data: any, status = 200): Response {
|
export function jsonResponse(data: unknown, status = 200): Response {
|
||||||
return new Response(JSON.stringify(data), {
|
return new Response(JSON.stringify(data), {
|
||||||
status,
|
status,
|
||||||
headers: { 'Content-Type': 'application/json' }
|
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 const VALID_STATUSES = ['draft', 'published'] as const
|
||||||
export type Status = (typeof VALID_STATUSES)[number]
|
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)
|
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 const VALID_POST_TYPES = ['post', 'essay'] as const
|
||||||
export type PostType = (typeof VALID_POST_TYPES)[number]
|
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)
|
return VALID_POST_TYPES.includes(type)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -54,7 +54,7 @@ export function createProjectFormStore(initialProject?: Project | null) {
|
||||||
isDirty,
|
isDirty,
|
||||||
|
|
||||||
// Methods for controlled mutation
|
// Methods for controlled mutation
|
||||||
setField(key: keyof ProjectFormData, value: any) {
|
setField(key: keyof ProjectFormData, value: unknown) {
|
||||||
fields[key] = value
|
fields[key] = value
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -67,7 +67,7 @@ export const toast = {
|
||||||
messages: {
|
messages: {
|
||||||
loading: string
|
loading: string
|
||||||
success: string | ((data: T) => string)
|
success: string | ((data: T) => string)
|
||||||
error: string | ((error: any) => string)
|
error: string | ((error: unknown) => string)
|
||||||
},
|
},
|
||||||
options?: ToastOptions
|
options?: ToastOptions
|
||||||
) => {
|
) => {
|
||||||
|
|
@ -82,7 +82,7 @@ export const toast = {
|
||||||
},
|
},
|
||||||
|
|
||||||
// Custom toast with full control
|
// Custom toast with full control
|
||||||
custom: (component: any, options?: ToastOptions) => {
|
custom: (component: unknown, options?: ToastOptions) => {
|
||||||
return sonnerToast.custom(component, {
|
return sonnerToast.custom(component, {
|
||||||
...defaultOptions,
|
...defaultOptions,
|
||||||
...options
|
...options
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue