Dynamic return type based on provided select array
So I have this function:
And when I call it I want the return type to contain only the fields that were provided in the
select
parameter.
In the result above, billableUsers
contains all user_data
column values, how can I narrow it down? I tried a lot of things but I keep getting type errors.
I am using the kysely-codegen
library for the types.
Thanks for the help!Solution:Jump to solution
Took 2 hours but I think I figured it out.
Here's my solution for anyone else who might stumble upon this problem.
Feel free to leave better/smarter/faster/shorter alternatives.
```...
1 Reply
Solution
Took 2 hours but I think I figured it out.
Here's my solution for anyone else who might stumble upon this problem.
Feel free to leave better/smarter/faster/shorter alternatives.
Now:
correctly resolves to:
const billableUsers: {id: string, work_email: string}[]