Need help improving a custom helper
My dopamine with Kysely is quite high right now, so I am experimenting all sorts of things to create custom helpers for common use-cases.
Here's an example of a working demo https://old.kyse.link/?p=s&i=qkTHjgwIuyb847wjoRd3
Following is a trimmed snippet from the above mentioned demo, for which I need help.
Is it possible for me use the
month
helper without passing it the eb
instance explicitly?
I know for the most part the answer is NO. But still want to check my luck and see if there is something I am unaware of.Solution:Jump to solution
Yeah unfortunately typescript doesn't bend that way. We wouldn't need the whole
ExpressionBuilder
callback thingy anywhere if it did. We could just use free functions and they'd somehow catch the context through generics in the return value.
another option is month(eb)('created_at')
....3 Replies
Hey 👋
So far, only possible while passing
eb
as argument. Anything I tried resulted in <never, unknown>
Yeah, I suspected that.
I think passing
eb
explicitly is fine as well. Its just month('created_at')
reads a little better than month(eb, 'created_at')
Thanks a ton for looking into it 🙂Solution
Yeah unfortunately typescript doesn't bend that way. We wouldn't need the whole
ExpressionBuilder
callback thingy anywhere if it did. We could just use free functions and they'd somehow catch the context through generics in the return value.
another option is month(eb)('created_at')
.