-
Notifications
You must be signed in to change notification settings - Fork 283
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 #674 TypeScript issues with dynamic inserts #679
Fix #674 TypeScript issues with dynamic inserts #679
Conversation
Mind approving this @Minigugus & @karlhorky ? |
@alpharder can you show a TS Playground or CodeSandbox/StackBlitz with your Postgres.js code where this fails? Would be easier to review what it is you're doing here. |
Thanks, from a code perspective that looks reasonable. Do you have a documentation link for the My last question would be related to the ternary branches of the Line 180 in ebc101d
Line 186 in ebc101d
|
I guess the only documentation available is the
I'm afraid that for consistency we'd have to cover the whole |
Ok, I'll leave these last decisions up to @porsager then, whether that's good enough like this - code looks ok, although a bit complex. One last suggestion from my side: the suggested formatting of the union types in this PR is a bit unusual (see below) T extends readonly (object & infer R)[] ? (
readonly (Keys & keyof R)[] // sql(data, "prop", "prop2") syntax
|
[readonly (Keys & keyof R)[]] // sql(data, ["prop", "prop2"]) syntax
) :
T extends readonly any[] ? readonly [] :
T extends object ? (
readonly (Keys & keyof T)[] // sql(data, "prop", "prop2") syntax
|
[readonly (Keys & keyof T)[]] // sql(data, ["prop", "prop2"]) syntax
) : Often unions are formatted without parentheses and by putting the pipe character at the start of each option in the union, eg. here's what Prettier does: : T extends readonly (object & infer R)[]
?
| readonly (Keys & keyof R)[] // sql(data, "prop", "prop2") syntax
| [readonly (Keys & keyof R)[]] // sql(data, ["prop", "prop2"]) syntax
: T extends readonly any[]
? readonly []
: T extends object
?
| readonly (Keys & keyof T)[] // sql(data, "prop", "prop2") syntax
| [readonly (Keys & keyof T)[]] // sql(data, ["prop", "prop2"]) syntax
: |
@porsager Could you please merge this and issue a new release? |
@karlhorky @alpharder is there anything considered breaking changes in this PR? Asked another way - Am I gonna have a horde of angry Typescripters at my door if it goes in a minor release? 😂 |
Nope, they should be happy 😃 These changes are backwards-compatible |
Fixes #674
The problem was caused by the nature of how rest operator
...
is treated in TypeScript, implyingreadonly (Keys & keyof R)[]
to represent individual function arguments.[readonly (Keys & keyof R)[]]
represents exactly one argument of typereadonly (Keys & keyof R)[]