-
Notifications
You must be signed in to change notification settings - Fork 29.9k
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
[ws]: Add generics to the ServerOptions
#65501
Conversation
@vansergen Thank you for submitting this PR! This is a live comment which I will keep updated. 1 package in this PRCode ReviewsBecause this is a widely-used package, a DT maintainer will need to review it before it can be merged. You can test the changes of this PR in the Playground. Status
Once every item on this list is checked, I'll ask you for permission to merge and publish the changes. InactiveThis PR has been inactive for 24 days — it is still unreviewed! Diagnostic Information: What the bot saw about this PR{
"type": "info",
"now": "-",
"pr_number": 65501,
"author": "vansergen",
"headCommitOid": "c6faa74b2ff857d60964b1483edb5d339032e32d",
"mergeBaseOid": "06c07f9cdee106a10883ece2d368a244d96722c6",
"lastPushDate": "2023-05-15T18:35:17.000Z",
"lastActivityDate": "2023-05-29T20:32:21.000Z",
"hasMergeConflict": false,
"isFirstContribution": false,
"tooManyFiles": false,
"hugeChange": false,
"popularityLevel": "Critical",
"pkgInfo": [
{
"name": "ws",
"kind": "edit",
"files": [
{
"path": "types/ws/index.d.ts",
"kind": "definition"
},
{
"path": "types/ws/ws-tests.ts",
"kind": "test"
}
],
"owners": [
"loyd",
"mlamp",
"TitaneBoy",
"reduckted",
"teidesu",
"wojtkowiak",
"k-yle",
"cwadrupldijjit"
],
"addedOwners": [],
"deletedOwners": [],
"popularityLevel": "Critical"
}
],
"reviews": [
{
"type": "approved",
"reviewer": "Knyazhishche",
"date": "2023-05-29T20:32:21.000Z",
"isMaintainer": false
}
],
"mainBotCommentID": 1548400622,
"ciResult": "pass"
} |
🔔 @loyd @mlamp @TitaneBoy @reduckted @teidesu @wojtkowiak @k-yle @cwadrupldijjit — please review this PR in the next few days. Be sure to explicitly select |
Did anyone have a chance to take a look at this PR? |
Re-ping @loyd, @mlamp, @TitaneBoy, @reduckted, @teidesu, @wojtkowiak, @k-yle, @cwadrupldijjit: This PR has been out for over a week, yet I haven't seen any reviews. Could someone please give it some attention? Thanks! |
It has been more than two weeks and this PR still has no reviews. I'll bump it to the DT maintainer queue. Thank you for your patience, @vansergen. (Ping @loyd, @mlamp, @TitaneBoy, @reduckted, @teidesu, @wojtkowiak, @k-yle, @cwadrupldijjit.) |
With this new code, the package "webpack-dev-server" is broke. I have the follow error node_modules@types\ws\index.d.ts:328:18 Type 'Server' is not generic. this will happen with all angular projects that use |
Yes same issue here as @JansenMoscol. All our builds are broken as well! |
@vansergen seconding this. we have the same issue, was this actually meant to be a "patch" release? |
No, it should be a major release according to |
from what i can gather making an angular project with angular 13 and making a dev build (using In case someone finds this PR while trying to solve it for themselves, down-patching by overriding dependencies in package.json works as a workaround.
|
Do you experience the same thing after webpack/webpack-dev-server#4899 is merged |
my project uses an older version of angular (@angular-devkit/build-angular@13.3.11) and it's webpack-dev-server seems to be pinned to |
Same problem, this breaks extensions to socket: import type WS from 'ws'
import { WebSocketServer } from 'ws'
interface Socket extends WS.WebSocket {
// ...
}
const socketServer: WS.Server<Socket> = new WebSocketServer({
noServer: true,
}) |
@lyswhut Now, there is no need to use generics. Try the following import { WebSocket, WebSocketServer } from "ws";
class Socket extends WebSocket {
// ...
}
const socketServer = new WebSocketServer({ noServer: true, WebSocket: Socket }); |
For some reason I only extended the type of socket, is there a way to make this work? import { type WebSocket, WebSocketServer } from 'ws'
interface Socket extends WebSocket {
// ...
}
const socketServer = new WebSocketServer<Socket>({
noServer: true,
}) Or mark it as breaking change? It does break some apps. |
Yes.
|
The first option would mean changing a lot of existing code.
@vansergen I tried this but it doesn't work: import { WebSocket, WebSocketServer } from 'ws'
interface Socket extends WebSocket {
id?: string
// ...
}
const socketServer = new WebSocketServer({
noServer: true,
WebSocket: WebSocket as unknown as Socket,
})
socketServer.on('connection', (socket, request) => {
console.log(socket.id)
}) |
This broke our angular project too. Please revert this. |
I agree. We can't build |
Could you provide an example? I explained above how to adopt to the latest version. |
@vansergen For the angular builds, I don't believe it's a problem with the codebase. With the angular builds, the problem is in a nested dependency of The solution here would be to move version |
The problem has been fixed in the webpack-dev-server@4.15.1 |
@masterqwerty It seems that "webpack-dev-server": "4.15.0", A new PR should be created to bump it. |
In our project we don't control the version of
We're using an older version of Angular, and upgrading to the fixed version would require a major version bump to Angular, and we're not in a position to migrate just yet. |
I found a temporary solution. I added the following code to the package.json file. "overrides": { Node.js version >= v16.14.0. should be. See: https://ruleoftech.com/2022/override-nested-npm-dependency-versions This is not a permanent solution. Also, those who use angular old version may not be able to update node.js version. |
@tahsinpol I agree. Even after my PR this will not fix the issue in older angular version and needs to move to a new |
* fix(ws): add generics to the server options * test(ws): add generics to `WebSocket` and `IncomingMesage`
Changes
req
object type.WebSocket
generic (used the same approach as [Node]: Update http request listeners #61922 )Before (
req instanceof http.IncomingMessage
)After (no generics at all)
Breaking changes
Related PRs
WebSocket
class websockets/ws#2007IncomingMessage
class websockets/ws#2122Checklist
npm test <package to test>
.If changing an existing definition: