What's the best way to use Pick with Selectable/Insertable/Updatable?
I am newer to typescript so fully possible missing something obvious here. But if I try to Pick from a table schema wrapped in Selectable/Insertable/Updateable it doesn't seem to infer the actual type of the column.
Example (first screenshot): x has no typescript issue here (just warns its unused in this fake code). "test" type shows resolving as:
Versus if I actually reference UserTable (second screenshot) I get TS Error:
But there is warning in the docs: "// You should not use the table schema interfaces directly." so I've tried to avoid refering UserTable directly.
Solution:Jump to solution
Actually I think this is environmental - I found there is a kysely sandbox and I couldn't repro there - it works perfect there in how I showed/you showed in the "better yet". I am going to close this and thanks again @koskimas
3 Replies
Your first example:
creates a type like this:
If you want the type of an individual column, you need to do something like this:
Or better yet:
Your second example attempts to assign a function to a variable that has the
email
column's type. I have no idea what you wanted it to do, but you can't assign a function to what I assume to be a string.Thanks for checking this out. Yup I definitely think you misunderstood.
To recap, you can see in first screenshot I did what your "better yet" shows (the User type for it is in fact
Selectable<UserTable>
as can be seen in second screenshot and referenced in the OP "But if I try to Pick from a table schema wrapped in Selectable/Insertable/Updateable...").
When you said "my first example" you pasted not what I attempted but what I wrote in the OP that the pick type in my first example/your "better yet" shows in VS code to resolve to (when I hover over it). Of course that type would make no sense.
I used the function assignment to clearly show it doesn't error on something it should. Second screenshot example was just to demonstrate it does in fact error if I reference directly from UserTable.
(Upon review though I did see in my OP one small mistake which is I accidently pasted the intentionally wrong function assignment line again instead of the error for the second example - I've corrected that bit now.)Solution
Actually I think this is environmental - I found there is a kysely sandbox and I couldn't repro there - it works perfect there in how I showed/you showed in the "better yet". I am going to close this and thanks again @koskimas