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
Type inferred is wrong when using model constructor #2531
Comments
I've been proposing the change that apparently creates this issue. I am happy to help out for a bit to see if we find the reason for it and can maybe fix or mitigate it. I failed to reproduce the issue with my local setup, i.e. everything works on my end when I run the code I believe the example implies. This might happen due to insufficient setup of the customized query builder (see https://vincit.github.io/objection.js/recipes/custom-query-builder.html#extending-the-query-builder-in-typescript) or maybe due to version differences in typescript. I am currently using typescript 4.8.4. @lorenzopicoli Can you provide a minimal example including your TenantQueryBuilder setup and specifying your typescript version?
Hope any of these will help to push this issue further. 🤞🏼 |
Thank you for the quick reply @max-kahnt-keylight. I've managed to create reproducible repo: https://github.com/lorenzopicoli/objection-reproduce. You can run You'll see that I included a few things that I found out while testing.
Let me know if I can help with anything else, this looks like more and more like an edge case to me, but I can't figure out what exactly causes typescript to be confused. |
@lorenzopicoli Thank you for the reproduction example. It helped a lot. Some quick learnings to share: I believe the issue only happens with tsconfig.json's objection.js/typings/objection/index.d.ts Line 1577 in 8e8ff2f
#702 sounds strongly related. Edit: I can definitely see that a revert of the Constructor typing changes is reasonable given these difficulties. |
@lorenzopicoli This fix seems to build against the existing objection test typings, your issue example, and also my codebase :D. There are probably more places in objection's current typings this should be applied to for this to be ready for review. We should maybe add this use-case to the objection test typings as well such that the requirements become a bit more stable and well-defined, since some gaps will remain for sure. @lehni How would you feel about such an approach? Do you think it would be mergable? |
@max-kahnt-keylight thank you for working on this! I have to admit that my knowledge of TS is very limited, and I am not actually relying on typings so much in my daily work, so I can't fully judge this unfortunately. Perhaps @falkenhawk would be willing to have a look and chime in? |
I'd say let's roll out a version with 23b8ac1 reverted and take more time to figure out the proper solution, and make sure it won't cause other new issues. |
Thank you again @max-kahnt-keylight for taking the time to fix this. Just wanted to confirm that on my project changing |
After version 3.0.3, more specifically after this PR: #2399 I've been encountering a breaking change to types.
I define my own query builder like this:
Then I call the following function:
Before the PR mentioned, the type of qb would be
MyQueryBuilder<MyModel>
which would be correct.After the update the type becomes
QueryBuilder<Objection.Model>
If I change the code to have a constructor that doens't take any arguments then the code works again as expected. Reverting the changes from the PR also results in correct types
The text was updated successfully, but these errors were encountered: