Closed kavitakothari closed 1 month ago
Hey 👋
Can you provide a kyse.link that reproduces this?
Seems to work for me https://kyse.link/FLt0L
You can't do this
const orders = ["first_name asc", "last_name desc"]
...
.orderBy(orders)
since orders
is just an array of strings.
However, you can do this:
const orders = ["first_name asc", "last_name desc"] as const
...
.orderBy(orders)
as const
makes the type ('first_name asc' | 'last_name desc')[]
.
If the orders
array is user input, you need to validate it and then cast it.
Kysely documentation allows a space separated string for sortBy and sortOrder to be passed in to orderBy - https://kysely-org.github.io/kysely-apidoc/interfaces/SelectQueryBuilder.html#orderBy
However when this syntax is tested on the Kysely playground it gives an error
"argument of type "age desc" is not assignable to parameter of type 'OrderByExpression<From<Database, "person">, "person", AllSelection<From<Databased, "person">, "person">>'
This does not work in VsCode either when trying to pass in an array of strings for multiple sort. It gives an error