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
Add typing for RawBinding and ValueMap #3036
Conversation
Merging this would be highly appreciated! |
@arenddeboer Could you please test updated binding locally to confirm they are indeed correct? I am not familiar enough with this part to merge this confidently. |
types/knex.d.ts
Outdated
interface RawQueryBuilder { | ||
(sql: string, ...bindings: (Value | QueryBuilder)[]): QueryBuilder; | ||
(sql: string, bindings: (Value | QueryBuilder)[] | ValueMap): QueryBuilder; | ||
(sql: string, ...bindings: RawBinding): QueryBuilder; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can understand RawBinding being added, but aren't Value and QueryBuilder valid params as well? Shouldn't they be also kept?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree, I see no need to remove them.
@kibertoad I have tested the pull request as is and this indeed solves the issue with the bindings. |
@arenddeboer Wait, I only now noticed - does this PR even do anything? Isn't |
Sorry for the delay.
So to get bindings working like this, one does not have to change |
This makes me wonder... now that we have typings in knex repo it would be possible to actually write tests for typings. Not saying that it needs to be done in this PR. |
I agree and was considering mentioning this in my last reply. Not sure what the best way forward is for Typescript tests though, but it makes a lot of sense and would probably help reason about current and future changes. |
@lorefnon Could you please take a look if this change still makes sense after all the latest changes? |
The only change here is that I may not have the full clarity here, but I don't think this is (and ever was) very useful because typescript's inference should have done the right thing (even with the bindings we had before). It is likely that in the application there is somewhere an explicit type annotation (as For example:
But simply removing that type annotation, will fix this:
Nevertheless, if this makes someone's life simpler I can rebase this change against current master. |
@lorefnon No need to rebase per se, probably would be much easier to just do sensible changes separately. Just exposing ValueDict seems like a reasonable change to allow people type their code more explicitly (otherwise they would need to introduce some local types that would then duck-type to ValueDict on compilation). If you are still doing any changes to typings, could you include that part? |
As per #3036 (comment) I have exposed this and some other utility types in #3211. @cham11ng I am adding you as a co-author in this PR so your contribution wouldn't get lost. Please let me know if you are not ok with this. |
@lorefnon It's okay |
Ref: #3036 (comment) Co-authored-by: Sagar Chamling <sgr.raee@gmail.com>
Closing this in favour of #3211 |
Add typing for RawBinding and ValueMap
This was the error I was facing. Since, its type was not exported I had to include it in my codebase.
I've added
RawBinding
andValueMap
.