fix(expo-db-sqlite-persistence): resolve TS2322 when passing SQLiteDatabase to createExpoSQLitePersistence#1560
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (3)
🚧 Files skipped from review as they are similar to previous changes (2)
📝 WalkthroughWalkthroughThis PR standardizes on ChangesExpo SQLite Type Unification and Bridge Parameter Normalization
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
packages/expo-db-sqlite-persistence/e2e/expo-runtime-app/App.tsx (1)
180-183: ⚡ Quick winExtract repeated optional-params dispatch into one helper.
The same
params === undefined ? ... : ...branching is duplicated four times; centralizing it reduces drift risk between db and tx paths.♻️ Proposed refactor
+type CommandParams = Extract<ExpoRuntimeCommand, { params?: unknown }>['params'] + +function callWithOptionalParams<TResult>( + sql: string, + params: CommandParams, + withoutParams: (sql: string) => Promise<TResult>, + withParams: (sql: string, params: NonNullable<CommandParams>) => Promise<TResult>, +): Promise<TResult> { + return params === undefined + ? withoutParams(sql) + : withParams(sql, params) +} @@ - return command.params === undefined - ? database.getAllAsync(command.sql) - : database.getAllAsync(command.sql, command.params) + return callWithOptionalParams( + command.sql, + command.params, + (sql) => database.getAllAsync(sql), + (sql, params) => database.getAllAsync(sql, params), + ) @@ - return command.params === undefined - ? database.runAsync(command.sql) - : database.runAsync(command.sql, command.params) + return callWithOptionalParams( + command.sql, + command.params, + (sql) => database.runAsync(sql), + (sql, params) => database.runAsync(sql, params), + ) @@ - return command.params === undefined - ? transaction.transaction.getAllAsync(command.sql) - : transaction.transaction.getAllAsync(command.sql, command.params) + return callWithOptionalParams( + command.sql, + command.params, + (sql) => transaction.transaction.getAllAsync(sql), + (sql, params) => transaction.transaction.getAllAsync(sql, params), + ) @@ - return command.params === undefined - ? transaction.transaction.runAsync(command.sql) - : transaction.transaction.runAsync(command.sql, command.params) + return callWithOptionalParams( + command.sql, + command.params, + (sql) => transaction.transaction.runAsync(sql), + (sql, params) => transaction.transaction.runAsync(sql, params), + )As per coding guidelines,
Extract common logic into utility functions when identical or near-identical code blocks appear in multiple places.Also applies to: 189-192, 250-253, 259-262
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@packages/expo-db-sqlite-persistence/e2e/expo-runtime-app/App.tsx` around lines 180 - 183, Extract the repeated optional-params branching into a single helper (e.g., getAllWithOptionalParams) that takes an executor object (database or transaction) and the command, and calls executor.getAllAsync(command.sql) when command.params is undefined or executor.getAllAsync(command.sql, command.params) otherwise; replace the four duplicate ternary uses (the blocks referencing command.params and database.getAllAsync) with calls to this helper so both db and tx code paths use the same implementation.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@packages/expo-db-sqlite-persistence/e2e/expo-runtime-app/App.tsx`:
- Around line 180-183: Extract the repeated optional-params branching into a
single helper (e.g., getAllWithOptionalParams) that takes an executor object
(database or transaction) and the command, and calls
executor.getAllAsync(command.sql) when command.params is undefined or
executor.getAllAsync(command.sql, command.params) otherwise; replace the four
duplicate ternary uses (the blocks referencing command.params and
database.getAllAsync) with calls to this helper so both db and tx code paths use
the same implementation.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 9b45186f-368c-4078-9f7b-1ed5f469dd3b
📒 Files selected for processing (7)
.changeset/six-ties-leave.mdpackages/expo-db-sqlite-persistence/e2e/expo-runtime-app/App.tsxpackages/expo-db-sqlite-persistence/e2e/runtime-protocol.tspackages/expo-db-sqlite-persistence/src/expo-sqlite-driver.tspackages/expo-db-sqlite-persistence/tests/helpers/expo-emulator-database-factory.tspackages/expo-db-sqlite-persistence/tests/helpers/expo-emulator-runtime.tspackages/expo-db-sqlite-persistence/tests/helpers/expo-sqlite-test-db.ts
🎯 Changes
The basic usage pattern for
createExpoSQLitePersistenceproduced a TS2322 error:The root cause was that
ExpoSQLiteQueryabledefinedgetAllAsyncandrunAsyncwith locally-defined loose types (ReadonlyArray<unknown> | Record<string, unknown>) for bind params. expo-sqlite'sSQLiteDatabasedefines these methods using strict TypeScript overloads, which TypeScript treats as incompatible with the optional params form using a different type, makingSQLiteDatabaseunassignable toExpoSQLiteQueryable.What changed
Replaced the locally-defined
ExpoSQLiteBindParamsandExpoSQLiteRunResulttypes in the driver with direct imports ofSQLiteBindParamsandSQLiteRunResultfromexpo-sqlite, makingExpoSQLiteQueryablestructurally compatible with the realSQLiteDatabase.Changed
withExclusiveTransactionAsyncto match expo-sqlite's actual signature which returnsPromise<void>, not a genericPromise<T>. The driver captures the transaction result via a local variable to preserve the return value.Added
normalizeBindValueto validate bind parameter types at the driver boundary, replacing the previous untyped spread. Also addednormalizeRuntimeSqliteParamsin the emulator runtime to explicitly rejectUint8Arrayvalues before they get JSON-serialized as {} over the HTTP bridge.✅ Checklist
pnpm test.🚀 Release Impact
Summary by CodeRabbit
Bug Fixes
Refactor