-
-
Notifications
You must be signed in to change notification settings - Fork 98
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
Use sql
parameter string typing instead of explicit generics in Typescript
#495
Comments
Great suggestion @geekuillaume. That would be a significant DX boost. |
When/if that TS issue is resolved, please, ping me. As might be obvious from the message there, I have a simple prototype for type-checked SQL literals. |
I've gave it a stab in #520 😉 |
This has now been released as part of v2.3.0. |
Is your feature request related to a problem? Please describe.
This is a potential improvement to remove the need to explicitly specify the generic
<ISelectUserIdsQuery>
when using thesql
method. It's inspired by GraphQL codegenerator.Describe the solution you'd like
During the codegen operation, in addition of generating the IOperationQuery, IOperationResult and IOperationParams, we can add an overload of the
sql
method that specify the exact string passed as parameter.For example, when declaring the queries in typescript:
it would generate a new file (called "queries.types.ts" for example):
Then, in the original file, the import can be changed to
import {sql} from './queries.types.ts'
and thenselectUser
will be typed without any other change. This also links the query string to the typing, if the query is changed, the typing reverts to unknown which can then trigger other errors. This will prevent mistakes linked to changing the query but not regenerating the codegen.Notes
This would require changing the calling method from using a template string to a normal string parameter:
to
This is necessary until this typescript issue is fixed: microsoft/TypeScript#33304
The text was updated successfully, but these errors were encountered: