【问题标题】:Parameter 'event' implicitly has an 'any' type.ts(7006)参数“事件”隐式具有“任何”类型.ts(7006)
【发布时间】:2019-07-10 19:26:38
【问题描述】:

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

参数 'event' 隐含一个 'any' 类型.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 + "%";
});

【问题讨论】:

    标签: typescript electron


    【解决方案1】:

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

    所以如果你想完整地输入它,假设你已经导入了Electronevent 的类型是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;
    }
    

    【讨论】:

    • 工作正常。但我还有一个问题,为什么 event.senderId 不起作用?并且 event.sender.sendTo() 不起作用。这是什么原因。
    • 嗯,这是另一个问题。您是否尝试记录整个 event 对象以查看它具有的所有属性?
    • 是的,我看过属性,没有属性名senderId。但是这个属性存在于电子documentation
    • 嗯,除了 Electron 版本不同,我不知道是什么原因造成的
    猜你喜欢
    • 2021-07-14
    • 2023-03-08
    • 2023-01-02
    • 2018-05-30
    • 2021-06-09
    • 2021-07-20
    • 2020-02-20
    • 1970-01-01
    • 2019-12-13
    相关资源
    最近更新 更多