Closed
Description
What version of Elysia is running?
1.2.24
What platform is your computer?
Linux 6.13.5-arch1-1 x86_64
What steps can reproduce the bug?
Consider this example:
const app = new Elysia().get(
'/',
() => {
return {
name: 'a',
a: 'b'
}
},
{
response: { 200: t.Object({
name: t.String()
}})
}
)
What is the expected behavior?
It is expected that the response type for the get('/') handler is
{ name: string }` since that's what the response validation dictates.
What do you see instead?
Typescript inferes the type as the return type of the handler though: {name: string, a: string}
.
Additional information
- This also breaks Eden and EdenFetch: Type-inference incorrect when response validation is used eden#186 (comment)
- With my limited knowledge, i believe the problem is this line:
Line 1541 in 4ba6085
My naive approach would be something like this:
200: EmptyRouteSchema extends Schema ? Exclude<Handle, ElysiaCustomStatusResponse<any, any, any>> : Schema['response'][200]
If a schema is present then use it, otherwise go with the handler's return type.
Have you try removing the node_modules
and bun.lockb
and try again yet?
yep