fix: precise types for $unsafeUnscoped chains and sql() payloads#26
Merged
Conversation
Two type-precision fixes on the honest scoped-mutation facade, both observed as typecheck failures in a downstream consumer: - `.$unsafeUnscoped()` now returns a builder (UnscopedInsertBuilder) whose conflict/upsert chains preserve the table-precise `.returning(...)` row type via ForwardChainMethod, instead of widening to `Record<string, unknown>`. ForwardChainMethod is the return-rewriting sibling of the existing ForwardMethod: it keeps each conflict method's exact per-dialect argument types but retypes the return to ScopedInsertResult so a trailing `.returning()` infers columns from the target table. - Scoped `.values(...)` / `.set(...)` payloads accept Drizzle `sql` template expressions for individual column values, matching Drizzle's own mutation signatures (a raw SQL column value was previously rejected). No runtime change and no version bump — entries land under [Unreleased]; the release that ships them is cut separately. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
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
Two type-only precision fixes to the honest scoped-mutation facade already on
main. No runtime change, no version bump — entries land under[Unreleased]. The 0.8.0 release that ships them is a separate stacked PR (#25), intended to merge after this one is reviewed.The fixes
.$unsafeUnscoped()return precision. It now returnsUnscopedInsertBuilder<TRaw, TTable>instead of the bareTRaw. Conflict/upsert chains keep their exact per-dialect argument types but the trailing.returning(...)infers columns from the target table, instead of widening toRecord<string, unknown>.ForwardChainMethodis the return-rewriting sibling of the existingForwardMethod(types.ts): same dialect-gating, but it retypes the method's return toScopedInsertResultso.returning()stays table-precise.sqltemplate payloads. Scoped.values(...)/.set(...)now accept Drizzlesqlexpressions for individual column values (TableInsertValuemaps each field toT | SQL), matching Drizzle's own insert/update signatures.Why (evidence)
Built
mainas-is and overlaid it into a downstream consumer that uses both patterns. The two fixes map 1:1 to two independent typecheck-error families, and each is required:mainas-isSQL<unknown>not assignable and widened-returningerrorsmain+sql-payload fix only.$unsafeUnscoped()…returning()sites)main+ both fixesVerification
format:check,lint,typecheck,test(44) all green. Diff is 2 files:src/types.tsand a### Fixedblock under[Unreleased]inCHANGELOG.md.🤖 Generated with Claude Code