Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect type for ws.publish #830

Closed
klavinski opened this issue Sep 15, 2024 · 2 comments
Closed

Incorrect type for ws.publish #830

klavinski opened this issue Sep 15, 2024 · 2 comments
Labels
bug Something isn't working

Comments

@klavinski
Copy link

What version of Elysia is running?

1.1.12

What platform is your computer?

Darwin 24.1.0 arm64 arm

What steps can reproduce the bug?

In an Elysia.ws handler, add a response validator and use ws.publish, like this:

new Elysia()
    .ws( "/", {
        open: ws => {
            ws.publish( "channel", "hello" )
        },
        response: t.String()
    } )
    .listen( 3000 )

What is the expected behavior?

There should be no type error.

What do you see instead?

"hello" has a type error:

Argument of type string is not assignable to parameter of type { 200: string; }.

Additional information

Essentially, when response validates the type T, the type checking of data argument requires {200: T}. However, the execution expects T: if provided with a {200: T}, a validation error is thrown.

I believe a previous version had the correct type for the data argument: WS['data']['schema']['response'] instead of Route["response"].

Have you try removing the node_modules and bun.lockb and try again yet?

No.

@klavinski klavinski added the bug Something isn't working label Sep 15, 2024
@klavinski
Copy link
Author

The generated type for Eden Treaty's subscribe is also wrong. I currently use it like this:

treatyClient.websocketRoute.subscribe().subscribe( ( { data } ) => {
    const wellTypeData = data as unknown as ( typeof data )[ 200 ] )
} )

@SaltyAom
Copy link
Member

Fixed and published under 1.1.13 with test case included
see 1.1.12...1.1.13

If this doesn't fix the issue, feel free to tag me or reopen the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants