Skip to content

Unable to access base Event properties from CloseEvent, ErrorEvent & MessageEvent for WebSocket #3524

@eXhumer

Description

@eXhumer

Bug Description

MessageEvent inherits Event and is supposed to provide the properties of Event such as Event.type and Event.timeStamp to MessageEvent. However, any class inheriting Event (CloseEvent, ErrorEvent & MessageEvent) fails to make any of the base properties accessible and causes the typescript compiler to fail unless MessageEvent type gets replaced by any when trying to access the base event properties.

Reproducible By

The following code is successfully compiled by tsc compiler.

const ws = new WebSocket('ws://localhost:8080');

ws.onmessage = (ev) => {
  const e = ev as any;
  console.log(e.type);
  console.log(e.defaultPrevented);
  console.log(e.cancelable);
  console.log(e.timeStamp);
};

The following code will throw an error while trying to compile with tsc due to Property '' does not exist on type MessageEvent<any>.

const ws = new WebSocket('ws://localhost:8080');

ws.onmessage = (e) => {
  console.log(e.type);
  console.log(e.defaultPrevented);
  console.log(e.cancelable);
  console.log(e.timeStamp);
};

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    TypesChanges related to the TypeScript definitionsbugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions