Tulshi Das
Tulshi Das

Reputation: 478

Parameter 'event' implicitly has an 'any' type.ts(7006)

I am using typescript in electron application. Typescript shows

Parameter 'event' implicitly has an 'any' type.ts(7006)

Here is the code. So what should I do ?

ipcRenderer.on('download-progress', function (event, progressInfo: ProgressInfo) {
    document.getElementById('pbs_' + progressInfo.id).style.width = progressInfo.percent + "%";
    document.getElementById('pts_' + progressInfo.id).innerHTML = progressInfo.percent + "%";
});

Upvotes: 1

Views: 2445

Answers (1)

Kewin Dousse
Kewin Dousse

Reputation: 4027

As the documentation shows, ipcRenderer.on takes a event as second argument which you specified correctly. You can see the documentation on the event Object here.

So if you want to type it completely, assuming you have Electron imported already, event is of type Electron.Event :

ipcRenderer.on('download-progress', function (event: Electron.Event, progressInfo: ProgressInfo) {
    document.getElementById('pbs_' + progressInfo.id).style.width = progressInfo.percent + "%";
    document.getElementById('pts_' + progressInfo.id).innerHTML = progressInfo.percent + "%";
});

For reference, here is the generic Electron.Event's type definition :

interface Event extends GlobalEvent {
  preventDefault: () => void;
  sender: WebContents;
  returnValue: any;
  ctrlKey?: boolean;
  metaKey?: boolean;
  shiftKey?: boolean;
  altKey?: boolean;
}

Upvotes: 1

Related Questions