8000 App type inferrence messed up when validation is added · Issue #1108 · elysiajs/elysia · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
App type inferrence messed up when validation is added #1108
Closed
@ptrxyz

Description

@ptrxyz

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

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0