Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inaccurate Type Narrowing when using .selectAll on multiple tables #1094

Open
hughgardiner opened this issue Jul 31, 2024 · 0 comments
Open
Labels
bug Something isn't working typescript Related to Typescript

Comments

@hughgardiner
Copy link

hughgardiner commented Jul 31, 2024

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

Updated Playground with same name person_id columns

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working typescript Related to Typescript
Projects
None yet
Development

No branches or pull requests

2 participants