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

Fix WS types, current ones are broken #585

Merged
merged 1 commit into from
Nov 5, 2024
Merged

Conversation

ruizmarc
Copy link
Contributor

WS library has changed how types are exported and graphql-ws is breaking builds if type checking for libraries is active:

node_modules/graphql-ws/lib/use/ws.d.ts(5,28): error TS2339: Property 'prototype' does not exist on type 'typeof import("/ptp/node_modules/@types/ws/index")'.

node_modules/graphql-ws/lib/use/ws.d.ts(6,27): error TS2694: Namespace '"/ptp/node_modules/@types/ws/index"' has no exported member 'Server'.

I have just properly imported types so we can use the library without problems.

Let me know if you need anything else from me. Hope to see it released soon!

@ruizmarc ruizmarc changed the title Fix WS are broken, current ones are broken Fix WS types, current ones are broken Oct 25, 2024
Copy link
Owner

@enisdenjo enisdenjo left a comment

Choose a reason for hiding this comment

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

Thanks for the update! One small change request.

Also, does this work for older versions for ws? It wont be a breaking change? Furthermore, why aren't typechecks detecting this - does the @types/ws package need an update?

src/use/ws.ts Outdated Show resolved Hide resolved
@ruizmarc
Copy link
Contributor Author

Thanks for the update! One small change request.

Also, does this work for older versions for ws? It wont be a breaking change? Furthermore, why aren't typechecks detecting this - does the @types/ws package need an update?

image

Checking at how types are defined it seems Server and WebSocketServer are equivalents, but Server as name is no longer exported. As useServer uses the interface of WebSocketServer as parameter, anyone using Server should have compatible types.

I guess types were not crashing because in tsconfig you have: skipLibCheck as true, which skips types from libraries. As in my project we check lib types, I could see the problem.

@enisdenjo enisdenjo merged commit 2c603ad into enisdenjo:master Nov 5, 2024
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants