-
Notifications
You must be signed in to change notification settings - Fork 572
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
Unable to access base Event
properties from CloseEvent
, ErrorEvent
& MessageEvent
for WebSocket
#3524
Comments
@KhafraDev @Uzlopak @panva wdyt? |
I don't follow, the types are set up to extend Lines 85 to 89 in cab6011
Lines 135 to 141 in cab6011
Lines 104 to 120 in cab6011
|
I think the problem lies in Lines 25 to 26 in 5f81898
The |
Some history of why it was added: #1740 Is there an easy workaround? Is this even needed anymore? @Ethan-Arrowood @andrewbranch |
I did a bit more digging, I think I figured out what the exact issue is. With the type inference being used, typescript infers the following declare var Event: {
prototype: Event;
new(type: string, eventInitDict?: EventInit): Event;
readonly NONE: 0;
readonly CAPTURING_PHASE: 1;
readonly AT_TARGET: 2;
readonly BUBBLING_PHASE: 3;
}; Even if you use If you try accessing the readonly values, typescript will incorrectly think they are actually there and not complain when trying to access a non-existent property. import { WebSocket } from 'undici';
import { WebSocketServer } from 'ws';
const wss = new WebSocketServer({ port: 8080 });
wss.on('connection', function connection(ws) {
ws.send('something');
});
const ws = new WebSocket('ws://localhost:8080');
ws.onmessage = e => {
console.log('e.NONE', e.NONE);
console.log('e.CAPTURING_PHASE', e.CAPTURING_PHASE);
console.log('e.AT_TARGET', e.AT_TARGET);
console.log('e.BUBBLING_PHASE', e.BUBBLING_PHASE);
console.log('e.data', e.data);
};
process.on('SIGINT', () => {
console.log('Closing WebSocket server');
wss.close();
process.exit();
}); Console output
|
I have found a fix by getting rid of the |
undici is currently at
|
Confirmed issue to be fixed with the |
Bug Description
MessageEvent
inheritsEvent
and is supposed to provide the properties ofEvent
such asEvent.type
andEvent.timeStamp
toMessageEvent
. However, any class inheritingEvent
(CloseEvent
,ErrorEvent
&MessageEvent
) fails to make any of the base properties accessible and causes the typescript compiler to fail unlessMessageEvent
type gets replaced byany
when trying to access the base event properties.Reproducible By
The following code is successfully compiled by tsc compiler.
The following code will throw an error while trying to compile with tsc due to
Property '' does not exist on type MessageEvent<any>
.Expected Behavior
Base properties of
Event
class accessible from inherited classes.Logs & Screenshots
None
Environment
macOS 15.1 Beta (24B5035e), node v22.6.0, undici v6.19.8
Additional context
The text was updated successfully, but these errors were encountered: