Improve TypeScript type safety by removing unnecessary as any casts - #230
Merged
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR systematically improves TypeScript type safety across the storage layer by replacing unsafe
as anycasts with more precise type annotations. The changes maintain runtime behavior while providing better compile-time type checking and improved code clarity.Key Changes
as anycasts: Replaced genericas anycasts with specific types likeEntity[keyof Entity],Record<string, unknown>, andValueOptionTypethroughout all storage implementationsentityRecord,insertRecord,updatedRecord) instead of repeatedly casting the same valueSqliteTabularStorageby removing intermediatev: anyvariable and usingvaluedirectly with proper type narrowingPostgresTabularStorageandSupabaseTabularStoragewith explicit type checksBaseSqlTabularStoragewith clearer type guardsdb.prepare<any, ...>todb.prepare<Entity, ...>for better type inference in pagination queries@ts-ignorecomments to explain why they're necessary (e.g., "SQLite typing for variadic bindings is overly strict for our union")as Record<string, unknown>pattern consistently across all storage implementations for object property accessImplementation Details
https://claude.ai/code/session_01633fDrUYTYDYgaP69XwsBN