-
Notifications
You must be signed in to change notification settings - Fork 89
Types for WebSocketPair #84
Comments
export {}
declare global {
interface WebSocket {
accept(): void;
}
class WebSocketPair {
0: WebSocket;
1: WebSocket;
}
interface ResponseInit {
webSocket?: WebSocket;
}
} |
the doc is now available at https://developers.cloudflare.com/workers/runtime-apis/websockets |
Any updates? |
Try adding a pull request, it might make it faster for them to make changes if all they have to do is review your code. |
export { }
declare global {
interface CloudflareWebsocket {
accept(): unknown;
addEventListener(event: 'close', callbackFunction: (code?: number, reason?: string) => unknown): unknown;
addEventListener(event: 'error', callbackFunction: (e: unknown) => unknown): unknown;
addEventListener(event: 'message', callbackFunction: (event: { data: any }) => unknown): unknown;
/**
* @param code https://developer.mozilla.org/en-US/docs/Web/API/CloseEvent
* @param reason
*/
close(code?: number, reason?: string): unknown;
send(message: string|Uint8Array): unknown;
}
class WebSocketPair {
0: CloudflareWebsocket; // Client
1: CloudflareWebsocket; // Server
}
interface ResponseInit {
webSocket?: CloudflareWebsocket;
}
} |
Warning to anyone else using these types: Using sepbot's suggestion (#84 (comment)) has the effect of adding This would be fine if Cloudflare Workers actually implemented the complete WebSocket spec, but it doesn't. For example, the I suggest using instead something like OwenDelahoy's suggestion (#84 (comment)) will narrowly defines only the features actually supported by CF workers. |
Auto-Generated Types Types are now automatically generated with releases by parsing the runtime's source code, and merging in overrides/docs defined in this repository (for generics, overloads, comments, etc). webworker no longer needs to (and shouldn't) be included in tsconfig lib. The final merged AST that's used to render the TypeScript types, workers.json, is also included in the repository. This could be used to generate bindings for other languages that compile to WebAssembly. Rust output is coming soon. Closes: #55, #75, #76, #81, #84, #96, #97, #100, #101, #102, #105, #106, #107, #108
Any plans for adding types related to websockets as seen in https://github.com/cloudflare/workers-chat-demo?
There doesn't seem to be any documentation on the the cloudflare docs so even writing it myself would be difficult. 😢
The text was updated successfully, but these errors were encountered: