fix(parse): type a column wrapped in parentheses - #338
Merged
Conversation
Query<DB, 'select (id) as x from users'> // was { x: unknown }[]
StrictRow<DB, 'select (id) as x from users'> // same
Two things had to be true for `(id)` to resolve, and neither was.
IsFunctionCall matched it, because the leading `${string}` in
`${string}(${string})` also matches the empty string, so the expression was
typed as a call to a function named `''`. It now requires a name.
That alone left `(id)` to be looked up as a literal column name, so the
parenthesized entry unwraps a group holding nothing but a column reference.
A group carrying parens of its own is left alone (a nested call is a call),
and so is a scalar subquery, which is a parenthesized group whose meaning is
the query inside it.
Strict mode's behaviour was the odd part worth naming: it resolved `id`
successfully on the way through and returned unknown anyway.
Fixes #288
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
tiagolauer
force-pushed
the
fix/288-paren-column
branch
from
August 2, 2026 13:04
816e418 to
5026d56
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 #288.
The bug
Expected
{ x: number }. Strict mode even validatesidsuccessfully along the way and still returnsunknown.The fix
Two things:
IsFunctionCall<'(id)'>returned true — the leading${string}in${string}(${string})also matches the empty string, so the expression was typed as a call to a function named''. It now requires a non-empty name.That alone leaves
(id)to be looked up as a literal column name, so the parenthesized entry now unwraps a group that holds nothing but a column reference. Two groups are deliberately left alone: one carrying parens of its own (a nested call is still a call), and a scalar subquery, whose meaning is the query inside it —tests/scalar-subquery.test-d.tscaught that one going red mid-change.The unwrap sits in the parenthesized-entry branch rather than in
ResolveColumnType, so it costs nothing for ordinary columns.Verification
tests/parenthesized-column.test-d.ts, eight cases. Four red on master:(id) as xin normal and strict mode, a qualified(u.name), and one among ordinary columnsunknown column: naem)count(*),lower(name)and a scalar subquery are unchangedtsc --noEmitclean, 192 runtime tests pass, budget 194,776 (+2,290 — the unwrap plus the name check on paren-carrying expressions).