fix(params): name the placeholder whose types conflict - #332
Merged
Conversation
Params<DB, 'select id from users where id = $1 or name = $1'>
// was [never]
A repeated placeholder intersects the types it was read with, and
`number & string` is `never`. A tuple holding never is uncallable with any
argument list at all, the empty one included, and the compiler explains that
as a chain of "not assignable to never" - the failure mode #230 already
treated as a bug in its own right, because it is invisible.
Rejecting the query is the right call: pg refuses inconsistent deduced
parameter types too. So the rejection stays and the diagnosis is added -
QueryTypeError<'conflicting types for $1'>, naming the token as written.
An already-conflicting slot is left alone rather than intersected again, so
a third occurrence does not rename the error.
Costs 1,467 instantiations (192,486 -> 193,953, 97% of the budget), all of
it the extra conditional in the merge step.
Fixes #302
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
tiagolauer
force-pushed
the
fix/302-conflicting-param-types
branch
from
August 2, 2026 13:03
fd91210 to
b522f48
Compare
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.
Fixes #302.
The bug
Every call is rejected, including the zero-argument one, behind an opaque "not assignable to never" chain. Rejecting the query is defensible — pg refuses inconsistent deduced parameter types too — but nothing told the user what went wrong or where. #230 treated a
nevertuple as a bug for exactly this reason: the failure mode is invisible.The fix
SetSlotintersects on repeat (Head & Type), andnumber & stringisnever. The merge step now checks for that and producesQueryTypeError<'conflicting types for $1'>, naming the token as written —$1,@v,:v.An already-conflicting slot is kept rather than intersected again, so a third occurrence does not rename the error.
Verification
tests/conflicting-params.test-d.ts, eight cases. Four red on master:@nameand:namespellings each report their own token[QueryTypeError<...>, string | null])Four controls stay pinned: a repeat against the same type still collapses to one slot (numbered, named, and across a join), and two distinct placeholders are unaffected.
tsc --noEmitclean. Budget 193,953, up 1,467 from master's 192,486 (97% of 200,000) — the cost of one extra conditional in the merge step.