-
Notifications
You must be signed in to change notification settings - Fork 303
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
Standard WebSocket
type returned instead of type from @cloudflare/workers-types
#1775
Comments
Workaround: declare module '@cloudflare/workers-types/experimental' {
export interface DurableObjectState extends OriginalDurableObjectState {
acceptWebSocket: (ws: WebSocket, tags?: string[]) => void
getWebSockets: (tag?: string) => WebSocket[]
getWebSocketAutoResponseTimestamp: (ws: WebSocket) => Date | null
getTags: (ws: WebSocket) => string[]
}
export declare const WebSocketPair: {
new (): {
0: WebSocket
1: WebSocket
}
}
} |
I ran into this as well. I don't think it's actually a cloudflare issue though. The issue (at least for me) was that [1] It was being added via |
@russelldavis I still believe it's a CloudFlare issue as the second screenshot from within CloudFlare type definitions file shows a modal which lists the return type as I will investigate what you said and report back. |
That's correct and expected. The Cloudflare library defines |
I ran into this issue a couple months ago when a package in my project was using the WebSocket type from lib.dom.d.ts, the solution for me was to add the following declaration extending the WebSocket type with the @cloudflare/workers-types WebSocket type.
|
@russelldavis is correct here—this is likely because
|
Version
Expected
deserializeAttachment()
exists onWebSocket
type returned byDurableState.getWebSockets()
Actual
DurableState.getWebSockets()
returns typeglobalThis.WebSocket
(standard type as defined byMDN Reference
):Suggestion
The types file does in fact include a type for the Cloudflare implementation of
WebSocket
which includes this signature, but this is not the Type which is returned.Anecdote
Could this be due to the
WebSocket
type definition coming later in the types file than theDurableObjectState
definition?The text was updated successfully, but these errors were encountered: