Discriminated Unions from AppType
Hi there! I had a question about the returned type of
hc<typeof app>
. I have an API route that returns 400
and { success: false, error: SomeTypes }
. Generally I would expect this to create a discriminated union on result.ok
or on body.success
(or both!) but neither seems to work.
This seems to be related to returning c.json()
multiple times in my route, but in theory I would expect this to consolidate types.
I've attached some screenshots as an example. In the last screenshot instead of success: boolean
it should be a literal, success: false
which would allow me to use it as a discriminate. Would love any insight folks have!


2 Replies
discriminating by status code works:
also including a
success
flag in the response data might be overkill, but if you really want to, you'd need to set it as a literal:
Thank you! Yeah I figured out last night that I can discriminate on status code and it works!