I'm trying to grab 2 articles from my database and for each article, I want to get all its tags. I'm using jsonArrayFrom to bundle up the tags for each article. The weird thing is that I get the exact result that I was expecting, but Typescript keeps telling me that something is wrong.
Here is the full code of my kysely query
const data = await db
.selectFrom("blog_articles as a")
.orderBy("a.published_at", "desc")
.limit(2)
.select([
"a.slug",
jsonArrayFrom(
db
.selectFrom("blog_article_tags as bat")
.innerJoin("blog_tags as t", "t.slug", "bat.tag_slug")
.select(["t.slug", "t.name", "t.stage"])
.whereRef("bat.article_slug", '=', 'a.slug'),
).as("tags"),
])
.execute();
But, here's where I'm stuck.
.whereRef("bat.article_slug", "=", "a.slug")
While hovering over a.slug
typescript throws me this error
Argument of type "a.slug" is not assignable to parameter of type 'ReferenceExpression<DB & { bat: BlogArticleTags; } & { t: BlogTags; }, "bat" | "t">'.
What is funny to me, is that I get the exact result I was expecting to get, the only problem is that Typescript seems to not like it at all.