typescript - 参数“事件”隐式具有“任何”类型.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 + "%";
});
解决方案
如文档所示,ipcRenderer.on
将event
您正确指定的第二个参数作为第二个参数。您可以在此处查看有关事件对象的文档。
因此,如果您想完全输入它,假设您已经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;
}
推荐阅读
- javascript - 基于 onclick 添加和删除 CSS 类
- javascript - 如何在模板字符串中使变量可选?
- openstack - 我对Openstack Token很好奇,它是关于Horizon、Keystone和Nova之间发行Scoped的起点
- python - 为什么使用 streamlit 的缓存而不是常规缓存?
- vb.net - 我的登录表单显示 OLE DB 查询不起作用
- kubernetes - Openstack (train) Populate Magnum 数据库错误
- python - 为什么字节数组不显示所有参数?(打印字节数组)
- javascript - 如何防止在 js window.opener 上切换到开启器选项卡在 Firefox 中重新加载
- c# - 正则表达式匹配字符后“”之间的正负数和文本
- python - 模块“cellpose.utils”没有属性“use_gpu”`