user776686
user776686

Reputation: 8655

Handling the type of event data in TypeScript

I'm trying to convert my JavaScript code into TypeScript (1.8.9) and I am wondering what is the correct way declare or cast the data attached to event.

self.onmessage = function(e: Event){
    if(e.data.schedules) processSchedules(e.data.schedules)
};

The data portion gets marked red by PHPStorm. Should I cast it to some interface or any in order to dismiss TS error?

Upvotes: 6

Views: 7777

Answers (1)

Aaron Beall
Aaron Beall

Reputation: 52133

Your event should be a MessageEvent, not Event:

self.onmessage = (e:MessageEvent) => {
    if (e.data.schedules)
        // ...
}

Upvotes: 7

Related Questions