New type error in 0.26.3
I recently upgraded from 0.26.1 to 0.26.3 and I'm getting a type error trying to call a reusable expression builder that used to work.
They query I'm calling it from has a bunch of other tables joined, but it have
MzCatalogMzRoles as r
so I would expect this to work
The type error is pretty unfortunate, I can't make much sense of it. I've attached it to the post in case it is useful. Any suggestions appreciated!21 Replies
In case it wasn't clear, the function is called like this:
I dug into this further, and it seems like the presence of a left join somehow triggers this, though it's not clear why.
This seems to be the relevant bit of the typescript error:
The old types were wrong. Left joined tables are nullable, so you need to use something like
Nullable being
@koskimas thanks for the response, unfortunately that didn't seem to fix the problem, I still see the same type error
Hey 👋🏻
Can you provide a kyse.link ?
@Igal sorry I didn't see your message! Here is a link: https://kyse.link/?p=s&i=SOTpUvdbZzJKCQJdlX77
it doesn't seem to fail though, what version of typescript is the playground running?
I'm on 5.1.3
I tried downgrading to 5.0.4, which appears to be the version in the playground, but I still get the error locally, I'm not really sure what's going on
maybe there is something else in my project that's required to reproduce the error, I'm not sure
I created a github repo that shows the issue: https://github.com/RobinClowers/kysely-type-error
GitHub
GitHub - RobinClowers/kysely-type-error
Contribute to RobinClowers/kysely-type-error development by creating an account on GitHub.
just
can you push your tsconfigs?
Yes, I'll do that later tonight
I didn't have a tsconfig in that example though, so it should repro with the defaults
defaults on my machine might differ from yours
changing to:
makes it work
Nullable<MzCatalogMzRoles>
causes an error, and feels wrong.
because "mz_catalog.mz_roles as r"
is MzCatalogMzRoles
and not Nullable<MzCatalogMzRoles>
@Igal thanks for getting back to me! I finally had a chance to try this out, and it doesn't work with left joins. I've pushed an update to that repo also including my tsconfig, but here is the new code:
@koskimas originally suggested the Nullable, since left joined relations are nullable, however, I think that wasn't quite right, since the mz_roles relation was an inner join...
It seems like we need a way to express that there may be some nullable relations included, but I have no good idea what that would look like
@Igal or @koskimas any chance you can take a look at my updated code? I posted it ^ but also in this repo: I created a github repo that shows the issue: https://github.com/RobinClowers/kysely-type-error It's blocking me from upgrading to typescript 5.2 😦
GitHub
GitHub - RobinClowers/kysely-type-error
Contribute to RobinClowers/kysely-type-error development by creating an account on GitHub.
Unknown User•14mo ago
Message Not Public
Sign In & Join Server To View
Thanks, I'll take a look
Super weird, using the Nullable helper seems to work in the playground, but not in my project
I even tried downgrading typescript to the same version used in the project
Unknown User•14mo ago
Message Not Public
Sign In & Join Server To View
I don't understand why the pick would be any different though? It still suffers from the same left join nullable issue
oh interesting, that does fix it though
@emiliewood thanks! I glossed right over the pick when I first read your response
I wish I understood why that works though...
Unknown User•14mo ago
Message Not Public
Sign In & Join Server To View
oooooh:
When you leftJoin a table that has a column that some other table also has, that column becomes nullable too because it gets overridden by the similarly named columnthat actually makes a ton of sense oh, but this still doesn't work if I left join a table that also includes on oid column 😢
Unknown User•14mo ago
Message Not Public
Sign In & Join Server To View
@emiliewood I figured out a way around this limitation that worked for my case, FYI https://github.com/kysely-org/kysely/issues/670#issuecomment-1783588105
GitHub
Question: Reusable select query helpers · Issue #670 · kysely-org/k...
Hi all, thanks for such a great library! I am currently using Kysely v0.26.1 with the Postgres Dialect. On this version I am able to create handy little reusable selections which I can pass into th...
I used a subquery instead of an expression builder