-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix Typescript type inference for returning()
to better support wildcard ("*") calls
#3444
Comments
returning()
to better support wildcard ("*"} callsreturning()
to better support wildcard ("*") calls
Mildly OT but maybe enable a zero-parameter .returning() which automatically means return all columns as a possible fix for this |
#3446 adds overrides that special case '*' so that the returned value will be the complete record.
This is unlikely to get you what you want because |
I also noticed that travis no longer run |
Thanks for the fast and thorough response to this. |
Released in 0.19.5 |
Environment
Knex version: 0.19.3
Database + version: Postgres 11
OS: Windows 10, WSL
@lorefnon - Hopefully you can address this... Or at least tell me if I am wrong.
Bug
When using
.returning()
in a Query Builder chain, it's possible to pass in a wildcard ("*") to indicate that you want all of a table's columns returned with the result.For example, when using Typescript Generics:
One expects
queryResult
's type to beUser[]
here, but it is actuallyPartial<User>[]
.This result makes sense when calling
returning()
with a column identifier (e.g. -returning("id")
), but not when it is called with a wildcard. When called with a wildcard, the result set is an array of fully qualifiedUser
objects, not partial ones.Note:
I know you can pass the
User
type toreturning()
more directly, like so:And get the expected result... But this bug is more about the type inference from the main Query Builder to
returning()
.Suggested Fix:
Maybe update the definition to something like:
The text was updated successfully, but these errors were encountered: