kysely
kysely copied to clipboard
Inaccurate Type Narrowing when using `.selectAll` on multiple tables
I'm curious how feasible it is to have the typescript response types accurately reflect the correct types based on the order of .selectAll('table') statements.
For example:
const rows = await db
.selectFrom("person")
.leftJoin("pet", "pet.person_id", "person.person_id")
.selectAll("person")
.selectAll("pet")
.execute();
Because this generates
select person.*, pet.*
the pet fields take priority in the output, which makes person_id possibly null given the fact that we are performing a left join
However, the generated response type says person_id is not nullable. if you reverse the order, the expected outcome of person_id being non-nullable is accurate as the `person.person_id field will always be present