Skip to content

Fix incorrect typings for Server class #152

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

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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ declare namespace WebSocketStream {
type WebSocketDuplex = Duplex & { socket: WebSocket };

class Server extends WebSocket.Server {
on(event: 'connection', cb: (this: WebSocket, socket: WebSocket, request: http.IncomingMessage) => void): this;
on(event: 'error', cb: (this: WebSocket, error: Error) => void): this;
on(event: 'headers', cb: (this: WebSocket, headers: string[], request: http.IncomingMessage) => void): this;
on(event: 'listening', cb: (this: WebSocket) => void): this;
on(event: 'stream', cb: (this: WebSocket, stream: WebSocketDuplex, request: http.IncomingMessage) => void): this;
on(event: string | symbol, listener: (this: WebSocket, ...args: any[]) => void): this;
on(event: 'connection', cb: (this: WebSocket.Server, socket: WebSocket, request: http.IncomingMessage) => void): this;
on(event: 'error', cb: (this: WebSocket.Server, error: Error) => void): this;
on(event: 'headers', cb: (this: WebSocket.Server, headers: string[], request: http.IncomingMessage) => void): this;
on(event: 'listening', cb: (this: WebSocket.Server) => void): this;
on(event: 'stream', cb: (this: WebSocket.Server, stream: WebSocketDuplex, request: http.IncomingMessage) => void): this;
on(event: string | symbol, listener: (this: WebSocket.Server, ...args: any[]) => void): this;
}

function createServer(opts?: WebSocket.ServerOptions, callback?: () => void): Server;

Choose a reason for hiding this comment

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

Suggested change
function createServer(opts?: WebSocket.ServerOptions, callback?: () => void): Server;
function createServer(opts?: WebSocket.ServerOptions, callback?: (...args: any[]) => void): Server;

I don't mind raising this as a separate PR, but this callback can take parameters,

if you look whats passed into the callback you can see that this is passed into this.on('stream', cb) in server.js

which is a method on its super class WebSocketServer which is part of the ws package

Screenshot 2024-03-18 at 14 00 45
In there they have many different callback types

Copy link
Author

Choose a reason for hiding this comment

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

my brother in christ, this has been open for 4 years now

Choose a reason for hiding this comment

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

Ah actually there is another ticket raised about this here #158 - don't worry

Choose a reason for hiding this comment

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

Changes look Good!

Expand Down