elysia
elysia copied to clipboard
`ws` type is not exported making it harder to store ws (WebSocket) objects in a TypeScript compliant way
What version of Elysia.JS is running?
0.8.17
What platform is your computer?
Darwin 23.2.0 arm64 arm
What steps can reproduce the bug?
import { Elysia } from "elysia";
const webSockets = new Set();
export const messagesRouter = new Elysia({
prefix: "/messages",
});
messagesRouter.ws("", {
open(ws) {},
});
What is the expected behavior?
I should be able to provide a type argument to new Set()
.
What do you see instead?
Unable to provide type argument to new Set()
.
Additional information
No response
Having the same issue. In a previous version of Elysia, I managed to jump into the inferred value and copy it in order to type things:
// Copied from inferred value so we can type check the map
type WS = ElysiaWS<
ServerWebSocket<{}>,
MergeSchema<UnwrapRoute<InputSchema<never>, {}>, {}>
>;
const connections = new Map<string, WS>();
However after upgrading it, it is no longer valid. It's possible it will continue to work by repeating the process, but this is overall cumbersome and it would be nice with a solid type to use.
FWIW, the currently accepted type for Elysia v 1.0.11 is this (but will likely stop working in a future update):
import { ServerWebSocket } from "bun";
import { TSchema } from "elysia";
import { TypeCheck } from "elysia/dist/type-system";
import { ElysiaWS } from "elysia/dist/ws";
type WS = ElysiaWS<
ServerWebSocket<{
validator?: TypeCheck<TSchema>;
}>,
any,
any
>