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

[@types/express-ws] Correct incorrect typing for websocket in express-ws types #69518

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions types/express-ws/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ declare namespace expressWs {
interface Instance {
app: Application;
applyTo(target: RouterLike): void;
getWss(): ws.Server;
getWss(): ws.WebSocketServer;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ws defines WebSocketServer as a synonym of Server by declaring a const and an interface. What's the advantage of switching? Based only on the types, I'd prefer Server since it's the original. But I know nothing about ws except what I got from reading index.d.ts.

}

type WebsocketRequestHandler = (ws: ws, req: express.Request, next: express.NextFunction) => void;
type WebsocketRequestHandler = (ws: ws.WebSocket, req: express.Request, next: express.NextFunction) => void;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ws is a synonym of ws.WebSocket, although I think the new code is easier to understand.

type WebsocketMethod<T> = (route: core.PathParams, ...middlewares: WebsocketRequestHandler[]) => T;

interface WithWebsocketMethod {
Expand Down