Skip to content

Improve TypeScript type safety by removing unnecessary as any casts - #230

Merged
sroussey merged 1 commit into
mainfrom
claude/remove-unnecessary-casting-zxhWn
Feb 25, 2026
Merged

Improve TypeScript type safety by removing unnecessary as any casts#230
sroussey merged 1 commit into
mainfrom
claude/remove-unnecessary-casting-zxhWn

Conversation

@sroussey

Copy link
Copy Markdown
Collaborator

Summary

This PR systematically improves TypeScript type safety across the storage layer by replacing unsafe as any casts with more precise type annotations. The changes maintain runtime behavior while providing better compile-time type checking and improved code clarity.

Key Changes

  • Removed unnecessary as any casts: Replaced generic as any casts with specific types like Entity[keyof Entity], Record<string, unknown>, and ValueOptionType throughout all storage implementations
  • Introduced intermediate typed variables: Created properly-typed intermediate variables (e.g., entityRecord, insertRecord, updatedRecord) instead of repeatedly casting the same value
  • Improved boolean conversion logic: Simplified boolean-to-integer conversion in SqliteTabularStorage by removing intermediate v: any variable and using value directly with proper type narrowing
  • Enhanced numeric conversion: Cleaned up numeric type conversions in PostgresTabularStorage and SupabaseTabularStorage with explicit type checks
  • Better blob handling: Improved blob/Uint8Array conversion logic in BaseSqlTabularStorage with clearer type guards
  • Refined generic type parameters: Updated db.prepare<any, ...> to db.prepare<Entity, ...> for better type inference in pagination queries
  • Improved comment clarity: Updated @ts-ignore comments to explain why they're necessary (e.g., "SQLite typing for variadic bindings is overly strict for our union")
  • Consistent record casting pattern: Applied as Record<string, unknown> pattern consistently across all storage implementations for object property access

Implementation Details

  • All changes are backward compatible with no runtime behavior modifications
  • Type safety improvements enable better IDE support and catch potential type errors at compile time
  • The refactoring follows a consistent pattern across multiple storage backends (SQLite, Postgres, Supabase, InMemory, FileSystem, IndexedDB)
  • Maintains existing error handling and event emission logic

https://claude.ai/code/session_01633fDrUYTYDYgaP69XwsBN

Replace `as any` with more precise type assertions across all tabular
storage implementations (Sqlite, Postgres, Supabase, InMemory, FsFolder,
IndexedDb). Key changes:
- Replace `return null as any` with `return null as Entity[keyof Entity]`
- Remove redundant double-casts like `const v: any = value as any`
- Replace `(entity as any)[key]` with `(entity as Record<string, unknown>)[key]`
- Use `Record<string, string | number>` for sort comparisons instead of `as any`
- Replace `as any[]` with proper typed arrays (ValueOptionType[], Entity[])

https://claude.ai/code/session_01633fDrUYTYDYgaP69XwsBN
@sroussey
sroussey merged commit 0f3b60c into main Feb 25, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants