首页 > 解决方案 > 参数“事件”隐式具有“任何”类型.ts(7006)

问题描述

我在电子应用程序中使用打字稿。打字稿显示

参数“事件”隐式具有“任何”类型.ts(7006)

这是代码。所以我该怎么做 ?

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 + "%";
});

标签: typescriptelectron

解决方案


如文档所示,ipcRenderer.onevent您正确指定的第二个参数作为第二个参数。您可以在此处查看有关事件对象的文档。

因此,如果您想完全输入它,假设您已经Electron导入,event则类型为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 + "%";
});

作为参考,这里是通用 Electron.Event 的类型定义:

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

推荐阅读