-
Notifications
You must be signed in to change notification settings - Fork 469
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 hinting for .execute
values from .input
types
#1336
Comments
I think the typings probably need to be updated in the types library if you want that to work, no? |
Thanks for the quick reply
|
Even simpler example: stmt.input('user_id', Int); // only user_id prepared statement
await stmt.prepare(`DELETE FROM users WHERE id = @user_id`);
await stmt.execute({ name, email, user_id: this.getId() }); // there is no .input for name and email SQL returns |
Well, there's no reason we couldn't warn against this kind of usage (it would be pretty bad practice to provide an object with more data than required for the execution), but in this kind of example we'd be forcing otherwise fine requests to fail. In your latest example, this statement would execute fine, the problem would come when you didn't provide enough parameters for the defined inputs... This feels a little bit too much like hand-holding and putting the developer on rails and also what unit tests are for (the errors you point out would be detected easily with some tests that asserted the application was correctly inserting to the database). |
😁 |
Type hinting is very helpful and reducing debugging time. In this case I'd very like if TS type hinting could point to obvious errors on the
execute
stageExample - in this case I removed the brackets from getId function to illustrate the problem
Or even simpler:
Expected behaviour:
stmt object already knows the
user_id
prop should be a number, but gets a function insteadI'd expect the code to fall if
execute
will get the object with wrong value typeThe ideal case would be if TS could point the non-expected type before I run the code
The text was updated successfully, but these errors were encountered: