K
Kysely•6mo ago
subhxsh

.filterWhere inference

I have this in a select
.coalesce(
fn
.jsonAgg(
jsonBuildObject({
id: ref("i.id"),
label: ref("i.label")
})
)
.filterWhere("i.id", "is not", null),
sql`[]`
)
.as("interests")
.coalesce(
fn
.jsonAgg(
jsonBuildObject({
id: ref("i.id"),
label: ref("i.label")
})
)
.filterWhere("i.id", "is not", null),
sql`[]`
)
.as("interests")
The result is being inferred as { id: string | null; label: string | null }[] Shouldn't it be { id: string; label: string }[] ?
Solution:
You can use .$narrowType for this.
Jump to solution
6 Replies
Igal (mobile)
Igal (mobile)•6mo ago
Hey 👋 Due to type complexity and performance filtering methods do not affect the output type.
subhxsh
subhxshOP•6mo ago
Ah. I see. But how do I remove the null manually. I've used .$notNull and it results in interests being any
Solution
Igal (mobile)
Igal (mobile)•6mo ago
You can use .$narrowType for this.
subhxsh
subhxshOP•6mo ago
Gotcha. Will check it out
Igal (mobile)
Igal (mobile)•6mo ago
Also, that sql template tag should be given an output type manually.
subhxsh
subhxshOP•6mo ago
Thank you. Typing the sql tag fixed it.

Did you find this page helpful?