gpt4 book ai didi

typescript - 参数 'event'隐式具有 'any'类型.ts(7006)

转载 作者:行者123 更新时间:2023-12-03 12:26:00 25 4
gpt4 key购买 nike

我在 Electron 应用中使用 typescript 。 typescript 显示

Parameter 'event' implicitly has an 'any' type.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作为您正确指定的第二个参数。您可以查看有关事件对象here的文档。

因此,如果您想完全键入它,假设您已经导入了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;
}

关于typescript - 参数 'event'隐式具有 'any'类型.ts(7006),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56966840/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com