-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Cannot augment WebSocket interface in TypeScript #1877
Comments
We don't ship nor maintain TypeScript type definitions. Please open this issue in the DefinitelyTyped repository. |
It's required to make a named export in this repository along with TS type definition. If only TS type definition is modified import { WebSocket } from 'ws'; will import nothing. |
@zimtsui the same happens if you do const { WebSocket } = require('ws'); It's not an issue in the library. I don't want to deal with TypeScript limitations/bugs. |
yes i see, and i said above
this is only a suggestion. and it needs little code change, may i make a PR? |
No thanks, again, I don't want changes only required for TypeScript. |
haha OK thank you O(∩_∩)O |
@zimtsui you can get around this with a hack. In This is my interface WebSocketWithId {
id: string;
}
declare interface WebSocket extends WebSocketWithId {}
declare namespace WebSocket {
type id = string;
}
declare module 'ws' {} When I use const ws = new Websocket('http://example.com'); // (parameter) ws: WebSocket
ws.id // (property) WebSocketWithSubscriptions.id: string |
Is there some logical reasoning for not wanting to change this or is this simply hate towards Typescript? |
Is there a reason for this? This isn't just a typescript change this would also make intellisense better for standard js users. |
Also eventually things are moving to ESM this package will need to at some point. This would be a good first change towards that. 😄 |
It is. What the OP requested can easily be done with no changes with CJS and it has nothing to do with intellisense. There is no |
Kinda sounds like you’re not aware of how named exports work. 🤔 |
I’d suggest you read up on named exports and the reasons to use them. It sounds like you have a personal opinion here that’s clouding your judgement. Also since node is moving to esm as I said this will eventually need to be moved to it. Negating the cjs comment. |
|
|
This is not an issue in |
In the end this wouldn't add any maintenance overhead, nothing would change for users importing it as they current do and people using typescript would get a better experience. Why exactly are you so against this? There's no downside apart from having to "support" typescript (that's being generous). |
It creates a property on the |
I don’t see why personal opinion should have any relevance here. This would help developers. This wouldn’t add any extra work for you. Why are you holding us back? This doesn’t make any sense. |
Maybe this is worth taking a vote with contributors of this repo? |
Sure. cc: @websockets/core @websockets/contributors |
Adding that property now is easy. Removing it, if/when the issue is fixed in TypeScript, would be a breaking change... just like |
There should be a way to have this work as a named export for esm while keeping the signature as you would like for cjs users. (I hope that makes sense) |
when adding a method
sendAsync
toWebSocket
, i have to augment the interface ofWebSocket
but this syntax above is illegal in TS, see microsoft/TypeScript#14080
TS only allows to augment a interface which is a named export, for example
this requires
WebSocket
is not default export but a named export.obviously, this is a bug of TS, not of ws. but you cannot look forward to TS fixing its bug. so i recommend ws exports a WebSocket within WebSocket, like
The text was updated successfully, but these errors were encountered: