Repository navigation
Fix select narrowing of snake case models, distinctOn(), clearSelect() and jsonExtract() (#16) - #341
Merged
Merged
Conversation
lehni
force-pushed
the
fix/typings-select-narrowing
branch
3 times, most recently
from
October 12, 2026 20:04
6dad49a to
7973963
Compare
…) and jsonExtract() (#16)
lehni
force-pushed
the
fix/typings-select-narrowing
branch
from
October 12, 2026 21:16
7973963 to
a457142
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.
What
Four fixes to the narrowing of result rows in strict mode, so that the types match what objection selects:
ColumnNameMapping: 'snakeCase'or'upperSnakeCase':select()removes the columns that it doesn't select from the rows. It left the camelCase properties in, as it omitted the snake case column names from them.distinctOn()takes columns likegroupBy()and doesn't narrow the rows, as objection doesn't select its columns.clearSelect()gives back the model rows, as objection selects all columns again. Aselect()after it starts over instead of adding to the cleared selection.jsonExtract()adds its alias to the rows, of unknown type, andorderBy()takes it. It doesn't narrow the rows, as it isn't a select: alone it comes next to all columns, withselect()(before or after it) next to the selected ones. Extractions without an alias, or several in one call, add properties of any name, like raw selections.jsonExtract()aliases are tracked by their own exported brand,ExtractedBrand<A>, next toSelectedBrand<A>, so that aselect()afterjsonExtract()still narrows the rows. Both are type aliases, so that the rows keep the implicit index signature of object types. The extracted aliases stay throughclearSelect()andwithGraphFetched()/withGraphJoined(), as they do at runtime.Stacked on #339.
Why
The rows claimed columns that weren't selected (snake case models,
clearSelect().select()), or rejected columns that were (distinctOn(),clearSelect()), andjsonExtract()aliases weren't typed at all.Breaking
distinctOn()takes column names,raw()andref(), likegroupBy(), instead of any selection.Tests
tests/ts/strict/snake-case.ts: unselected multi-word columns are gone, forsnakeCaseandupperSnakeCase.tests/ts/strict/select.ts:distinctOn(),clearSelect()(also withfirst()and a custom query builder) andjsonExtract()before and afterselect(), withorderBy(),clearSelect(),withGraphFetched()andwithGraphJoined(), and its rows assignable toRecord<string, unknown>.tests/ts/strict/declarations.ts: an exported function returning ajsonExtract()query.pnpm test:typingswith TypeScript 7, andtsc/tsc -p tests/ts/strictwith TypeScript 5.8.3, pass.Part of #53.