K
Kysely•4mo 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)•4mo ago
Hey 👋 Due to type complexity and performance filtering methods do not affect the output type.
subhxsh
subhxshOP•4mo 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)•4mo ago
You can use .$narrowType for this.
subhxsh
subhxshOP•4mo ago
Gotcha. Will check it out
Igal (mobile)
Igal (mobile)•4mo ago
Also, that sql template tag should be given an output type manually.
subhxsh
subhxshOP•4mo ago
Thank you. Typing the sql tag fixed it.
Want results from more Discord servers?
Add your server