Phase 1: Critical Type Fixes
- Fix useDraftRecovery type signature to accept () => string | null
(was incorrectly typed as string | null)
- Add TResponse generic parameter to AutoSaveStore interface
- Update all call sites to use function for draftKey reactivity
Phase 2: Robustness Improvements
- Remove non-null assertions in useFormGuards
- Capture autoSave in closures to prevent potential null access
- Make useFormGuards generic to accept any AutoSaveStore types
Documentation & Code Quality
- Document AlbumForm autosave initialization order
- Add comments explaining void operator usage for reactivity
- Fix eslint error: prefix unused _TResponse with underscore
These fixes address the critical issues found in PR review:
1. Type mismatch causing TypeScript errors
2. Non-null assertions that could cause crashes
3. Missing documentation for complex initialization patterns
Introduces createAutoSaveStore() using $state() for automatic reactivity.
New store provides cleaner API while maintaining backward compatibility.
Changes:
- New: src/lib/admin/autoSave.svelte.ts with createAutoSaveStore()
- Uses $state() for status and lastError (reactive getters)
- Export AutoSaveStore and AutoSaveStoreOptions types
- Add JSDoc with usage examples
- Update autoSaveLifecycle.ts to accept both old and new types
- Export AutoSaveController type from old file for compatibility
Old createAutoSaveController() remains unchanged for gradual migration.
Type checking passes with no new errors.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>