Self join breaks return type

Same issue as https://discord.com/channels/1043890932593987624/1286374226667896914 The return type of the query is never[]. If I remove the left join, things return to normal. The query works as expected, the result is just never[].
No description
6 Replies
SpoderMan
SpoderManOP3w ago
May be worth mentioning that doing the same query within the query API returns the expected type:
No description
SpoderMan
SpoderManOP3w ago
I've created a full example, hopefully I'm just missing something https://drizzle.run/vgpyb731hdqu7u73og9crp63
Mario564
Mario5643w ago
Hey there. Fixed by by using alias function instead of aliasedTable
import { alias } from "drizzle-orm/pg-core"

const parent = alias(users, "parent");
import { alias } from "drizzle-orm/pg-core"

const parent = alias(users, "parent");
@SpoderMan
SpoderMan
SpoderManOP3w ago
Interesting. Thank you! What's the TLDR of the difference between the 2?
Mario564
Mario5643w ago
Don't know honestly. I think aliasedTable is an outdated implementation of alias. The former is likely to be deprecated and then removed in v1
SpoderMan
SpoderManOP3w ago
Awesome, thanks a ton. For anyone else who was using this the same way I was, I have a tip. I was taking the result of aliasedTable and passing it through to a function using a function signature like this: function withChildren<T extends users>(parent: T) alias returns a slightly different type. There might be a better way to get that type, but this appears to be working type UserAlias = ReturnType<typeof alias<typeof users, "parent">>; Then I changed the function signature to function withChildren<T extends UserAlias>(parent: T)

Did you find this page helpful?